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;
using ll=long long;
using ld=long double;
using pear=pair<ll, ll>;
#define fi first
#define se second
#define nl << '\n'
#define uk << ' '
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
cin.exceptions(cin.failbit);
ll n;
cin >> n;
ll i;
vector<pair<ll, ll>> art(n+1);
for(i=1; i<=n; i++){
cin >> art[i].fi >> art[i].se;
}
vector<ll> pre(n+1);
sort(art.begin()+1, art.end());
for(i=1; i<=n; i++){
pre[i]=pre[i-1]+art[i].se;
}
ll maxi=LLONG_MIN, ans=0;
for(i=1; i<=n; i++){
maxi=max(maxi, art[i].fi-pre[i-1]);
ans=max(ans, pre[i]-art[i].fi+maxi);
}
cout << ans;
}
| # | 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... |