이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<pair<long long, long long> > v;
long long a, b, p[n], tmp[n], curr=0, ans=0;
for(int i=0; i<n; i++){
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
tmp[0]=p[0]=v[1].first-v[0].first-v[0].second;
for(int i=1; i<n-1; i++){
p[i]=p[i-1]+v[i+1].first-v[i].first-v[i].second;
tmp[i]=max(tmp[i-1], p[i]);
}
curr=v[0].second;
//cout << curr << endl;
for(int i=0; i<n; i++){
if(i>0) curr+=(v[i].second-v[i].first+v[i-1].first);
//cout << i << " " << curr << endl;
ans=max(ans, curr);
if(i>0) ans=max(ans, curr+tmp[i-1]);
}
cout << ans;
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... |