[BOJ 15234] Number Pairs
View as PDF
Submit solution
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text
Points:
1
Time limit:
2.0s
Memory limit:
512M
Problem types
Allowed languages
Given a sequence of N distinct integer numbers compute the number of pairs that sum to K.</p>
Example:
Given the sequence {1, 2, 3, 4, 5, 6}
- There are 1 pair of numbers that sums to 3: (1, 2)
- There are 1 pair of numbers that sums to 4: (3, 1)
- There are 2 pairs of numbers that sum to 5: (1, 4) and (3, 2)
- There are 2 pairs of numbers that sum to 6: (5, 1) and (4, 2)
- There are 3 pairs of numbers that sum to 7: (1, 6), (2, 5) and (3, 4).
- There are 2 pairs of numbers that sum to 8: (2, 6) and (5, 3)
- There are 2 pairs of numbers that sum to 9: (6, 3) and (5, 4)
- ...
Note that we consider that the pairs (1, 6) and (6, 1) are the same.
입력 형식
The first line will contain two integers N and K.</p>
N represents the number of elements in the sequence and K the goal value.
We want to know how many pairs of numbers sum to K.
The second line will contain N integers separated by spaces.
N <= 1000
The numbers in the sequence will be between 1 and 10^6.
출력 형식
An integer, the number of pairs that add K.
예제 입력
6 7
1 3 2 6 5 4
예제 출력
3
Comments