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;
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define lwb lower_bound
#define upb upper_bound
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x * y / __gcd(x, y)
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int mxN = 5e5 + 5;
const int block = 450;
const int base = 311;
const int LOG = 19;
int n;
pair<ll, ll> a[mxN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].fi >> a[i].se;
}
sort(a + 1, a + n + 1);
ll ans = 0;
for (int i = 1; i <= n; i++) {
ll s = 0;
for (int j = i; j <= n; j++) {
s += a[j].se;
ans = max(ans, s - a[j].fi + a[i].fi);
}
}
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... |