[BOJ 9728] Pair Sum
View as PDFYou are given an integer array of size N and an integer M. This array has (N*(N-1))/2 different pairs. You need to calculate how many of those pairs have the sum equal to M. For example, if the array is {1,2,3,4} and M is 5, then there are exactly 2 pairs {1,4} and {2,3} whose sum is equal to M.
입력 형식
The first line has a positive integer T, T <= 100,000, denoting the number of test cases. This is followed by each test case per line. </p>
Each test case consists of two lines. The first line contains 2 integers N and M separated by a single space. N is between 2 and 20,000 inclusive. The second line consists of the N integers separated by a single space, denoting the values of the given array. All the numbers in the array are between 1 and 1,000,000,000 inclusive. They are distinct and sorted in increasing order.
출력 형식
For each test case, the output contains a line in the format Case #x: R, where x is the case number (starting from 1) and R is the number of pairs whose sum is exactly the given M.
예제 입력
5
8 100
19 25 32 48 52 68 75 81
8 100
19 28 31 49 51 61 72 81
8 100
16 22 38 46 58 62 73 81
8 100
13 21 32 48 52 67 78 87
8 100
13 24 34 43 57 61 76 81
예제 출력
Case #1: 4
Case #2: 3
Case #3: 1
Case #4: 2
Case #5: 2
Comments