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>
#define fn(n) for(int i=1; i<=n; i++)
#define f1(n) for(int i=n; i>=1; i--)
#define no cout << "NO";
#define yes cout << "YES";
#define el cout << '\n';
#define a first
#define b second
using namespace std;
using ll=long long;
int n;
pair<ll, ll> a[500002];
ll f[500002];
ll res=-1e18;
ll cur=-1e18;
void nhap(){
cin >> n;
for(int i=1; i<=n; i++){
cin >> a[i].a >> a[i].b;
}
sort(a+1, a+n+1);
for(int i=1; i<=n; i++){
f[i]=f[i-1]+a[i].b;
}
}
void solve(){
for(int i=n; i>=1; i--){
cur=max(cur, f[i]-a[i].a);
res=max(res, cur+a[i].a-f[i-1]);
}
cout << res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
nhap();
solve();
}
# | 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... |