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 <iostream>
#include <algorithm>
#define int long long
using namespace std;
const int MAX_NOMBRE = 5e5+42;
pair<int, int> tableau[MAX_NOMBRE];
int nbTableau;
signed main() {
cin >> nbTableau;
for(int i = 0; i < nbTableau; i++) {
cin >> tableau[i].first >> tableau[i].second;
}
sort(tableau, tableau + nbTableau);
int fin = 0, valOpti = 0, sommeCur = 0;
for(int i = 0; i < nbTableau; i++) {
sommeCur += tableau[i].second;
int valCur = sommeCur - tableau[i].first + tableau[0].first;
if(valCur > valOpti) {
valOpti = valCur;
fin = i;
}
}
valOpti = 0; sommeCur = 0;
for(int i = fin; i >= 0; i--) {
sommeCur += tableau[i].second;
int valCur = sommeCur - tableau[fin].first + tableau[i].first;
valOpti = max(valOpti, valCur);
}
cout << valOpti;
}
# | 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... |