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;
typedef long long ll;
pair<ll, ll>dela[500050];
ll prefiksne[500050], manje[500050], vece[500050];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
for(int i=0; i<n; i++)cin>>dela[i].first>>dela[i].second;
sort(dela, dela+n);
prefiksne[0]=dela[0].second;
for(int i=1; i<n; i++)prefiksne[i]=dela[i].second+prefiksne[i-1];
manje[0]=dela[0].first;
vece[0]=LONG_MIN;
for(int i=1; i<n; i++)
{
vece[i]=prefiksne[i]-dela[i].first;
manje[i]=dela[i].first-prefiksne[i-1];
}
ll mn=LONG_MIN, rez=LONG_MIN;
//for(int i=0; i<n; i++)cout<<manje[i]<<" "<<vece[i]<<"/n";
for(int i=0; i<n; i++)
{
mn=max(mn, manje[i]);
rez=max(rez, mn+vece[i]);
}
cout<<rez;
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... |