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;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define mp make_pair
#define all(x) x.begin(), x.end()
#define Repp(i, l, r, a) for (int i = l; i < r; i += a)
#define Rep(i, l, r) Repp(i, l, r, 1)
#define For(i, n) Rep(i, 0, n)
#define Fori(i, n) Rep(i, 1, n + 1)
#define Each(x, v) for (auto x : v)
#define Repd(i, l, r) for (int i = r - 1; i >= l; i--)
#define Ford(i, n) Repd(i, 0, n)
#define endl "\n"
const ll INF = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int N; cin >> N;
pll data[N + 1];
Fori (i, N) cin >> data[i].fi >> data[i].se;
sort(data + 1, data + N + 1);
ll pref[N + 1];
pref[0] = 0;
Fori (i, N) pref[i] = pref[i - 1] + data[i].se;
ll ans = -INF, niki = INF;
Fori (i, N) {
niki = min(niki, pref[i - 1] - data[i].fi);
ans = max(ans, pref[i] - data[i].fi - niki);
}
cout << ans << endl;
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... |