fork download
  1.  
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class Main {
  6. static class Reader {
  7. final private int BUFFER_SIZE = 1 << 16;
  8. private DataInputStream din;
  9. private byte[] buffer;
  10. private int bufferPointer, bytesRead;
  11.  
  12. public Reader()
  13. {
  14. din = new DataInputStream(System.in);
  15. buffer = new byte[BUFFER_SIZE];
  16. bufferPointer = bytesRead = 0;
  17. }
  18.  
  19. public Reader(String file_name) throws IOException
  20. {
  21. din = new DataInputStream(
  22. new FileInputStream(file_name));
  23. buffer = new byte[BUFFER_SIZE];
  24. bufferPointer = bytesRead = 0;
  25. }
  26.  
  27. public String readLine() throws IOException
  28. {
  29. byte[] buf = new byte[64]; // line length
  30. int cnt = 0, c;
  31. while ((c = read()) != -1) {
  32. if (c == '\n') {
  33. if (cnt != 0) {
  34. break;
  35. }
  36. else {
  37. continue;
  38. }
  39. }
  40. buf[cnt++] = (byte)c;
  41. }
  42. return new String(buf, 0, cnt);
  43. }
  44.  
  45. public int nextInt() throws IOException
  46. {
  47. int ret = 0;
  48. byte c = read();
  49. while (c <= ' ') {
  50. c = read();
  51. }
  52. boolean neg = (c == '-');
  53. if (neg)
  54. c = read();
  55. do {
  56. ret = ret * 10 + c - '0';
  57. } while ((c = read()) >= '0' && c <= '9');
  58.  
  59. if (neg)
  60. return -ret;
  61. return ret;
  62. }
  63.  
  64. public long nextLong() throws IOException
  65. {
  66. long ret = 0;
  67. byte c = read();
  68. while (c <= ' ')
  69. c = read();
  70. boolean neg = (c == '-');
  71. if (neg)
  72. c = read();
  73. do {
  74. ret = ret * 10 + c - '0';
  75. } while ((c = read()) >= '0' && c <= '9');
  76. if (neg)
  77. return -ret;
  78. return ret;
  79. }
  80.  
  81. public double nextDouble() throws IOException
  82. {
  83. double ret = 0, div = 1;
  84. byte c = read();
  85. while (c <= ' ')
  86. c = read();
  87. boolean neg = (c == '-');
  88. if (neg)
  89. c = read();
  90.  
  91. do {
  92. ret = ret * 10 + c - '0';
  93. } while ((c = read()) >= '0' && c <= '9');
  94.  
  95. if (c == '.') {
  96. while ((c = read()) >= '0' && c <= '9') {
  97. ret += (c - '0') / (div *= 10);
  98. }
  99. }
  100.  
  101. if (neg)
  102. return -ret;
  103. return ret;
  104. }
  105.  
  106. private void fillBuffer() throws IOException
  107. {
  108. bytesRead = din.read(buffer, bufferPointer = 0,
  109. BUFFER_SIZE);
  110. if (bytesRead == -1)
  111. buffer[0] = -1;
  112. }
  113.  
  114. private byte read() throws IOException
  115. {
  116. if (bufferPointer == bytesRead)
  117. fillBuffer();
  118. return buffer[bufferPointer++];
  119. }
  120.  
  121. public void close() throws IOException
  122. {
  123. if (din == null)
  124. return;
  125. din.close();
  126. }
  127. }
  128.  
  129. public static void main(String[] args)
  130. throws IOException
  131. {
  132. Reader s = new Reader();
  133. int t=s.nextInt();
  134. while(t-->0){
  135. int n=s.nextInt();
  136. int a[]=new int[n];
  137. long tsum=0;
  138. for(int i=0;i<n;i++){
  139. a[i]=s.nextInt();
  140. tsum+=a[i];
  141. }
  142. Arrays.sort(a);
  143. long lsum=0,rsum=tsum;
  144. int i=0;
  145. for(i=0;i<n;i++){
  146. if(lsum+a[i]>=rsum)break;
  147. lsum+=a[i];
  148. rsum-=a[i];
  149.  
  150. }
  151. System.out.println(i);
  152. double ans=(lsum/(double)(i))+(rsum/(double)(n-i));
  153. System.out.println(ans);
  154. }
  155.  
  156. }
  157. }
  158.  
Success #stdin #stdout 0.07s 38724KB
stdin
2
2
4 5
5
2 2 2 2 2
stdout
1
9.0
2
4.0