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