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 ll long long
#define MAXN 500005
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
ll n, pfx[MAXN], r = 0;
pair<ll, ll> w[MAXN];
int main(){
cin >> n;
FOR(i, 1, n) cin >> w[i].first >> w[i].second;
sort(w + 1, w + 1 + n);
pfx[0] = 0;
FOR(i, 1, n) pfx[i] = pfx[i - 1] + w[i].second;
ll mn = -w[1].first;
FOR(i, 1, n){
r = max(r, (pfx[i] - w[i].first) - mn);
mn = min(mn, pfx[i] - w[i].first);
}
cout << r << 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... |