-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZCO13003.cpp
50 lines (44 loc) · 910 Bytes
/
ZCO13003.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[100005];
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n, k, i, l, r, mid, ans = 0, idx;
cin >> n >> k;
for (i = 0; i < n; i++)
{
cin >> arr[i];
}
sort(arr, arr + n);
for (i = n - 1; i >= 0; i--)
{
l = 0;
r = i;
idx = -1;
while (l < r)
{
mid = (l + r) / 2;
if (arr[mid] + arr[i] >= k)
{
r = mid;
}
else
{
l = mid + 1;
idx = max(idx, mid);
}
}
if (idx != -1)
{
//cout << "for " << arr[i] << " adding freq " << idx << endl;
ans += idx + 1;
}
}
cout << ans;
return 0;
}