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 ff first
#define ss second
using namespace std;
const long long INF = 0xf3f3f3f3f3f3f3f;
const int maxn = 5e5 + 5;
pair<int, long long> arr[maxn];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i].ff >> arr[i].ss;
sort(arr + 1, arr + 1 + n);
for (int i = 2; i <= n; i++)
arr[i].ss += arr[i-1].ss;
long long mi = -arr[1].ff;
long long ans = -INF;
for (int i = 1; i <= n; i++) {
ans = max(ans, arr[i].ss - arr[i].ff - mi);
mi = min(mi, arr[i].ss - arr[i+1].ff);
}
cout << ans << '\n';
}
signed main() {
solve();
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... |