Mediumtwo-pointerssortinghash
Count Pairs with Given Sum
Time limit 2 s · Memory 64 MBAcceptance: 25.0%Solved by: 1
Statement
The first line contains n, the second line contains n integers, the third line contains target. Print the number of index pairs (i < j) with a_i + a_j = target.
Examples
Example 1
Input
5 1 5 7 -1 5 6
Output
3
Example 2
Input
4 1 1 1 1 2
Output
6
Constraints
- 1 ≤ n ≤ 10^5
- -10^9 ≤ a_i, target ≤ 10^9