This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
const int m = (int) 1e5 + 10;
vector<int> a(m);
for (int i = 0; i < n; i++) {
int h, k;
cin >> h >> k;
a[h]--;
a[h - k]++;
}
for (int i = 0; i < m - 1; i++) {
a[i + 1] += a[i];
}
priority_queue<int> pq;
pq.emplace(0);
for (int i = m - 1; i >= 0; i--) {
while (pq.top() - 1 >= a[i] + 1) {
int b = pq.top();
a[i]++;
b--;
pq.pop();
pq.emplace(b);
}
pq.emplace(a[i]);
}
long long ans = 0;
while (!pq.empty()) {
int b = pq.top();
pq.pop();
ans += 1LL * b * (b - 1) / 2;
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |