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;
using ll = long long;
pair<int, int> a[100100];
ll qs[100100];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> a[i].first >> a[i].second;
}
sort(a + 1, a + 1 + n, greater<pair<int, int>>());
int now = 100000;
for (int i = 1;i <= n;i++) {
now = min(now, a[i].first);
int k = a[i].second;
if (k > now) {
qs[1]++;
qs[now + 1]--;
k -= now;
now = a[i].first;
}
qs[now + 1]--;
qs[now - k + 1]++;
now -= k;
}
ll ans = 0;
for (int i = 1;i <= 100000;i++) {
qs[i] += qs[i - 1];
ans += qs[i] * (qs[i] - 1) / 2;
}
cout << ans;
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... |