-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathhackrndm.cpp
More file actions
53 lines (44 loc) · 922 Bytes
/
hackrndm.cpp
File metadata and controls
53 lines (44 loc) · 922 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define inf 1000000000
using namespace std;
int main() {
int n,k;
scanf("%d%d", &n, &k);
map<int, int> nrs;
int x;
int sol = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
map<int,int>::iterator it = nrs.find(x+k);
if (it != nrs.end()) {
sol += it->second;
}
it = nrs.find(x-k);
if (it != nrs.end()) {
sol += it->second;
}
it = nrs.find(x);
if (it == nrs.end()) {
nrs[x] = 1;
} else {
++it->second;
}
}
printf("%d\n", sol);
return 0;
}