이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const long long N = 500000+10;
const long long mod = 1e9+7;
const long long inf = 1e18;
vector<int>a(N),b(N);
bool cmp(int i,int j) {
if(a[i] == a[j]) return b[i] < b[j];
return a[i] < a[j];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//pref[r]-a[r]-pref[l-1]+a[l]
int n,res=0;
cin >> n;
vector<int>pref(n,0),order(n,0);
for(int i=0;i<n;i++) {
cin >> a[i] >> b[i];
res = max(res,b[i]);
}
iota(order.begin(),order.end(),0);
sort(order.begin(),order.end(),cmp);
int mn = inf;
//for(int i=0;i<n;i++) cout << a[order[i]] << ' ' << b[order[i]] << endl;
for(int i=0;i<n;i++) {
pref[i] = b[order[i]];
if(i > 0) pref[i] += pref[i-1];
if(mn == inf) {
mn = -a[order[i]];
continue;
}
// cout << pref[i] << ' ' << mn << ' ' << a[order[i]] << endl;
res = max(res,pref[i]-mn-a[order[i]]);
mn = min(mn,pref[i-1]-a[order[i]]);
}
cout << res;
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... |