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>
#include <iostream>
using namespace std;
#define int int64_t
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin>>n;
vector<pair<int, int>>v;
for(int i = 0; i<n; ++i){
int a, b; cin>>a>>b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
vector<int>prefix(n);
prefix[0] = v[0].second;
for(int i = 1; i<n; ++i) prefix[i] = prefix[i-1] + v[i].second;
int ans = -1e18;
for(int i = 1; i<n; ++i){
int cur = prefix[i] - (v[i].first - v[0].first);
ans = max(ans, cur);
}
for(int i = 1; i<n-1; ++i){
if(v[i].first - v[0].first > prefix[i]) continue;
int diff = (v[i].first - v[0].first) - prefix[i-1];
if(diff > 0) ans += diff;
}
for(int i = 0; i<n; ++i) ans = max(v[i].second, ans);
cout<<ans;
cout<<'\n';
}
# | 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... |