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;
#define int long long
#define A first
#define B second
signed main(){
int n;
cin >> n;
pair<int , int> p[n+1];
for (int i = 1 ; i<=n ; i++){
int a , b;
cin >> a >> b;
p[i] = {a , b};
}
sort(p , p+n+1);
for (int i = 1 ; i<=n ; i++){
p[i].B += p[i-1].B;
}
int max = -1e18 , maxind = 0, min = 1e18;
for (int i = 1 ; i<=n ; i++){
if (p[i].B - p[i].A > max) { max = p[i].B - p[i].A; maxind =i ;}
}
for (int i = 1 ; i<=maxind ; i++){
if (p[i-1].B - p[i].A < min) min = p[i-1].B - p[i].A;
}
cout << max - min << '\n';
}
# | 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... |