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;
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int>> arr(n + 5);
for (int i = 1; i <= n; i++) cin >> arr[i].first >> arr[i].second;
sort(arr.begin() + 1, arr.begin() + n + 1);
vector<int> prefix(n +5 );
for (int i = 1; i <= n; i++) prefix[i] = arr[i].second + prefix[i - 1];
int mn = -prefix[0] + arr[1].first;
int ans = -1e18;
for (int i = 1; i <= n; i++) {
ans = max(ans, prefix[i] - arr[i].first + mn);
mn = max(mn, -prefix[i] + arr[i].first);
}
cout << ans << '\n';
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... |