#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;cin>>N;
vector<pair<int,int>> eser(N);
for(int i=0;i<N;++i)cin>> eser[i].first>>eser[i].second;
sort(eser.begin(), eser.end());
vector<long long> P(N + 1, 0);
for (int i = 0; i < N; ++i) {
P[i + 1] = P[i] + eser[i].second;
}
long long M_max = LLONG_MIN;
long long G_max = LLONG_MIN;
for (int j = 1; j <= N; ++j) {
M_max = max(M_max, eser[j-1].first - P[j-1]);
G_max = max(G_max, P[j] - eser[j-1].first + M_max);
}
cout << G_max;
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... |