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 MAXN 5001
long long n;
vector<pair<long long,long long>> vec;
long long pref[MAXN];
int main()
{
cin>>n;
vec.push_back({0,0});
for (long long i=1;i<=n;i++)
{
long long a,b;cin>>a>>b;
vec.push_back({a,b});
}
sort(vec.begin(),vec.end());
pref[0]=0;
for (long long i=1;i<=n;i++) pref[i]=pref[i-1]+vec[i].second;
long long ans=-LLONG_MAX;
for (long long i=1;i<=n;i++)
{
for (long long j=1;j<=i;j++) ans=max(ans,pref[i]-pref[j-1]-vec[i].first+vec[j].first);
}
cout<<ans<<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... |