-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path4.cpp
More file actions
36 lines (36 loc) · 739 Bytes
/
Copy path4.cpp
File metadata and controls
36 lines (36 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl "\n"
#define mod 1000000007
//Find all pairs on integer array whose sum is equal to given number.
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
int arr[n];
REP(i, 0, n) {
cin >> arr[i];
}
int ctr = 0;
unordered_map<int, int> m;
REP(i, 0, n) {
m[arr[i]]++;
}
REP(i, 0, n) {
ctr += m[k - arr[i]];
// cout << i << " " << k - arr[i] << " " << ctr << " ";
if (k - arr[i] == arr[i])
ctr--;
// cout << ctr << endl;
}
cout << ctr / 2;
}