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;
maximum = max(maximum,arr[i].second);
}
sort(arr,arr + N);
ll ptr = 0;
ll cur = arr[0].second;
for(ll i = 1;i < N;i++){
cur += arr[i].second;
cur -= (arr[i].first - arr[i - 1].first);
while(ptr < i){
if(cur + (arr[ptr + 1].first - arr[ptr].first) - arr[ptr].second > cur){
cur += (arr[ptr + 1].first - arr[ptr].first) - arr[ptr].second;
ptr++;
}else{
break;
}
}
maximum = max(maximum,cur);
}
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... |