#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int b, n, d, m;
void solve1()
{
vector <int> v;
for(int i = 0;i<n;i++)
{
int x;
cin >> x;
v.push_back(x);
}
long long answer = 0;
sort(v.begin(), v.end());
for(int i = 0;i<n-1;i++)
{
if(v[i+1]-v[i]>d) continue;
int l = i + 1, r = n - 1, mid;
while(l+1<r)
{
mid = (l+r)/2;
if(v[mid]-v[i]<=d) l = mid;
else r = mid - 1;
}
if(v[r]-v[i]<=d) answer += r - i;
else answer += l - i;
}
cout << answer << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> b >> n >> d >> m;
if(b==1) solve1();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1408 KB |
Output is correct |
2 |
Correct |
24 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1792 KB |
Output is correct |
2 |
Correct |
27 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1848 KB |
Output is correct |
2 |
Correct |
30 ms |
1824 KB |
Output is correct |
3 |
Correct |
29 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |