#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int MAXH = (int) 1e5;
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
vector <int> h(n + 1), k(n + 1), ord(n + 1);
for(i = 1; i <= n; i++) {
cin >> h[i] >> k[i];
ord[i] = i;
}
sort(next(ord.begin()), ord.end(), [&](const int &a, const int &b) {
return h[a] < h[b];
});
vector <int> cnt(MAXH + 1);
for(i = 1; i <= n; i++) {
int val = cnt[h[ord[i]] - k[ord[i]] + 1];
int pos = h[ord[i]];
while(cnt[pos] != val) {
k[ord[i]]--;
cnt[pos--]++;
}
int res = 0;
for(int step = 1 << 16; step; step >>= 1) {
if(res + step <= MAXH && cnt[res + step] > val) {
res += step;
}
}
while(k[ord[i]]--) {
cnt[++res]++;
}
}
ll ans = 0;
for(i = 1; i <= MAXH; i++) {
ans += 1LL * cnt[i] * (cnt[i] - 1) / 2;
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
2 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
768 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
716 KB |
Output is correct |
2 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
768 KB |
Output is correct |
2 |
Correct |
148 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
1024 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
1280 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1065 ms |
1784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
1752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1073 ms |
1996 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |