#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5e5;
const long long INF = 1e18;
struct art {
long long size;
int value;
};
art arts[MAX_N];
int main() {
int n;
cin >> n;
for ( int i = 1; i <= n; i++ )
cin >> arts[i].size >> arts[i].value;
sort( arts + 1, arts + 1 + n, []( art a, art b ) {
return a.size < b.size;
} );
long long maxCost = 0, sumValue = 0, maxPartial = -INF;
for ( int i = 1; i <= n; i++ ) {
maxPartial = max( maxPartial, -sumValue + arts[i].size );
sumValue += arts[i].value;
maxCost = max( maxCost, sumValue - arts[i].size + maxPartial );
}
cout << maxCost;
}
# | 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... |