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;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,l,p;
cin >> n;
vector<pair<int,int>>ciag;
vector<int>ciag2(1);
for(int i=0;i<n;++i){
cin >> l >> p;
ciag.push_back({l,p});
}
sort(ciag.begin(),ciag.end());
for(int i=0;i<n;++i){
ciag2.push_back(ciag2[i]+ciag[i].second);
}
int wynik=0,wynik2=0;
vector<int>maksy;
for(int i=0;i<n;++i){
wynik=max(ciag2[i]*-1+ciag[i].first,wynik);
maksy.push_back(wynik);
}
for(int i=0;i<n;++i){
wynik2=max(ciag2[i]*-1+ciag[i].first+maksy[i],wynik2);
}
cout << wynik2;
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... |