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 pii = pair<int, int>;
using ll = long long;
#define all(a) begin(a), end(a)
#define rep(a) for(int i = 0; i < a; i++)
#define each(i,a) for(auto&& i : a)
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<pii> a(n);
each(i, a) cin >> i.first >> i.second;
sort(all(a));
multiset<int> X; // i 番目に大さい境界から i + 1 番目に大さい境界までが i である
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);
}
ll ans = 0, cnt = 0;
for(auto p = X.end(); p-- != X.begin(); cnt++) ans += cnt * *p;
cout << ans << '\n';
}
# | 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... |