#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> p;
#define f first
#define s second
int n, ans = 0, cur = 0;
vector<p> artworks;
int bestprf = 0; // Initialize to 0 instead of LLONG_MAX/2
signed main(){
cin >> n;
for (int i = 0; i < n; i++){
int a, b;
cin >> a >> b; // size, value
artworks.push_back(make_pair(a, b));
}
sort(artworks.begin(), artworks.end()); // sort by size
for (auto [sze, val] : artworks){
cur += val;
ans = max(ans, cur - sze - bestprf);
bestprf = min(bestprf, cur - val - sze);
}
cout << ans << endl;
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... |