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 FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define FILES {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define ll long long
#define ull unsigned long long
#define pqueue priority_queue
#define pb push_back
#define fi first
#define se second
#define ld long double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
using namespace std;
void solve() {
int n;
cin >> n;
vector<pll>v(n);
vector<ll>vv(n);
for (int i = 0 ; i < n ; i++ ) {
cin >> v[i].fi >> v[i].se;
}
sort(all(v));
for (int i = 0 ; i < n ; i++ )
vv[i] = v[i].se;
for (int i = 1 ; i < n ; i++ ) {
v[i].se += v[i-1].se;
}
ll res = 0;
ll mx = 0;
//v[i].se - v[j].se - ( v[i].fi - v[j].fi)
for (int i = n-1 ; i >= 0 ; i-- ) {
ll tren = v[i].se - v[i].fi;
res = max(res, mx-tren+vv[i]);
mx = max(mx, tren);
//cout << mx << endl;
}
cout << res << endl;
}
int main () {
FAST
int t=1;
/*
cin >> t;
//*/
int i = 1;
while(t--) {
//cout << "Case #" << i++ << ": " ;
solve();
}
}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:59:9: warning: unused variable 'i' [-Wunused-variable]
59 | int i = 1;
| ^
# | 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... |