fork(1) download
  1. import java.util.InputMismatchException;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.PrintWriter;
  5. import java.util.Arrays;
  6. class LCPC12F{
  7. public static void main(String args[])throws IOException{
  8. InputReader sc = new InputReader(System.in);
  9.  
  10. int t = sc.nextInt();
  11. for(int q=1; q<=t; q++){
  12. int x = sc.nextInt(), n = sc.nextInt();
  13. int arr[] = new int[n], ans = 0;
  14. for(int i=0; i<n; i++)
  15. arr[i] = sc.nextInt();
  16. Arrays.sort(arr);
  17.  
  18. int j = 0, k = n-1;
  19. while(j<k){
  20. if(arr[j]+arr[k] == x){
  21. ans++;
  22. j++;
  23. }
  24. else if(arr[j] + arr[k]<x)
  25. j++;
  26. else
  27. k--;
  28. }
  29. pw.println(+q+". "+ans);
  30. }
  31. pw.flush();
  32. pw.close();
  33. }
  34. static class InputReader {
  35. private final InputStream stream;
  36. private final byte[] buf = new byte[8192];
  37. private int curChar, snumChars;
  38. private SpaceCharFilter filter;
  39.  
  40. public InputReader(InputStream stream) {
  41. this.stream = stream;
  42. }
  43.  
  44. public int snext() {
  45. if (snumChars == -1)
  46. throw new InputMismatchException();
  47. if (curChar >= snumChars) {
  48. curChar = 0;
  49. try {
  50. snumChars = stream.read(buf);
  51. } catch (IOException e) {
  52. throw new InputMismatchException();
  53. }
  54. if (snumChars <= 0)
  55. return -1;
  56. }
  57. return buf[curChar++];
  58. }
  59.  
  60. public int nextInt() {
  61. int c = snext();
  62. while (isSpaceChar(c)) {
  63. c = snext();
  64. }
  65. int sgn = 1;
  66. if (c == '-') {
  67. sgn = -1;
  68. c = snext();
  69. }
  70. int res = 0;
  71. do {
  72. if (c < '0' || c > '9')
  73. throw new InputMismatchException();
  74. res *= 10;
  75. res += c - '0';
  76. c = snext();
  77. } while (!isSpaceChar(c));
  78. return res * sgn;
  79. }
  80.  
  81. public long nextLong() {
  82. int c = snext();
  83. while (isSpaceChar(c)) {
  84. c = snext();
  85. }
  86. int sgn = 1;
  87. if (c == '-') {
  88. sgn = -1;
  89. c = snext();
  90. }
  91. long res = 0;
  92. do {
  93. if (c < '0' || c > '9')
  94. throw new InputMismatchException();
  95. res *= 10;
  96. res += c - '0';
  97. c = snext();
  98. } while (!isSpaceChar(c));
  99. return res * sgn;
  100. }
  101.  
  102. public int[] nextIntArray(int n) {
  103. int a[] = new int[n];
  104. for (int i = 0; i < n; i++) {
  105. a[i] = nextInt();
  106. }
  107. return a;
  108. }
  109.  
  110. public String readString() {
  111. int c = snext();
  112. while (isSpaceChar(c)) {
  113. c = snext();
  114. }
  115. StringBuilder res = new StringBuilder();
  116. do {
  117. res.appendCodePoint(c);
  118. c = snext();
  119. } while (!isSpaceChar(c));
  120. return res.toString();
  121. }
  122.  
  123. public String nextLine() {
  124. int c = snext();
  125. while (isSpaceChar(c))
  126. c = snext();
  127. StringBuilder res = new StringBuilder();
  128. do {
  129. res.appendCodePoint(c);
  130. c = snext();
  131. } while (!isEndOfLine(c));
  132. return res.toString();
  133. }
  134.  
  135. public boolean isSpaceChar(int c) {
  136. if (filter != null)
  137. return filter.isSpaceChar(c);
  138. return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  139. }
  140.  
  141. private boolean isEndOfLine(int c) {
  142. return c == '\n' || c == '\r' || c == -1;
  143. }
  144.  
  145. public interface SpaceCharFilter {
  146. public boolean isSpaceChar(int ch);
  147. }
  148. }
  149. }
Success #stdin #stdout 0.06s 27920KB
stdin
1
6 5
3 3 3 3 3
stdout
1. 4