110. Count Friend Pairs With Target Sum

Acceptance — 0 accepted 0 submissions

Medium
ArraysHashing
No companies listed
For a team game, pairs of students are formed whose skill points add up to exactly k.

Count the number of index pairs (i, j) with i < j and a[i] + a[j] = k.

Input Format
The first line has n.
The second line has n integers.
The third line has k.

Output Format
Print the number of pairs.

Constraints
• 1 ≤ n ≤ 10^5
• -10^9 ≤ value, k ≤ 10^9
• The answer can be large, so use long long or long.

Example 1

Input
5
1 5 7 -1 5
6
Output
3

Explanation Pairs: (1,5), (1,5) with the second 5, and (7,-1). Total 3.

Example 2

Input
4
1 1 1 1
2
Output
6

Explanation Every pair of the four 1s works: 6 pairs.

Example 3

Input
3
1 2 3
10
Output
0

Explanation No pair adds up to 10.

Acceptance —
Accepted 0
Submissions 0
Auto-save
Saved Ln 1, Col 1
Submit a solution to see its status here.
Input
Expected Output
3
No results yet
Run your code to test it against the sample cases.
Problem List