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