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;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
pair<ll,ll> arr[N];
ll maximum = 0;
for(ll i = 0;i < N;i++){
cin>>arr[i].first>>arr[i].second;
}
sort(arr,arr + N);
ll psumB[N + 1]; //1-indexed
psumB[0] = 0;
for(ll i = 1;i <= N;i++){
psumB[i] = psumB[i - 1] + arr[i - 1].second;
}
ll maxL = -1e18;
for(ll i = 0;i < N;i++){
maxL = max(maxL,arr[i].first - psumB[i]);
maximum = max(maximum,maxL + psumB[i + 1] - arr[i].first);
}
cout<<maximum<<'\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... |