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 endl '\n'
#define pb push_back
#define ll long long
#define int ll
const long long inf=1e18;
const int MOD=1e9+7;
const int N=5e5+5;
int best[N],prefval[N];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin>>n;
pair<int,int> p[n+1];
for(int i=1;i<=n;i++)cin>>p[i].first>>p[i].second;
sort(p,p+(n+1));
for(int i=1;i<=n;i++)prefval[i]=p[i].second+prefval[i-1];
int idx=1;
for(int i=1;i<=n;i++){
if(p[i].first>prefval[i-1]-prefval[idx-1]+p[idx].first)idx=i;
best[i]=idx;
}
int mx=0;
for(int i=1;i<=n;i++){
int ans=prefval[i]-prefval[best[i]-1]+p[best[i]].first;
ans-=p[i].first;
mx=max(mx,ans);
}
cout<<mx;
}
# | 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... |