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;
#define each(i,a) for(auto&& i : a)
int main(){
int n;
cin >> n;
vector<pair<int, int>> a(n);
each(i, a) cin >> i.first >> i.second;
sort(a.begin(), a.end());
multiset<int> X;
X.insert(0);
each(i, a){
auto [h, k] = i;
X.insert(h);
auto p = X.upper_bound(h - k), q = prev(p);
int next = *q + *p - h + k;
if(q != X.begin()) X.erase(q);
X.insert(next);
X.erase(p);
}
long ans = 0, cnt = 0;
for(auto p = X.end(); p-- != X.begin(); cnt++) ans += cnt * *p;
cout << ans << endl;
}
# | 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... |