#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[500001],p[500001];
int main() {
cin.tie(0)->sync_with_stdio(false);
int n;
cin >> n;
for (int i=0;i<n;i++) {
cin >> a[i] >> p[i];
}
ll mini=a[0],maxi=a[0];
ll s=p[0];
ll mx;
for (int i=1;i<n;i++) {
mx = max(p[i],max(s-maxi+mini,s-max(maxi,a[i])+min(mini,a[i])+p[i]));
if (s-max(maxi,a[i])+min(mini,a[i])+p[i] == mx) {
s+=p[i];
mini = min(mini,a[i]);
maxi = max(maxi,a[i]);
} else if (p[i] == mx){
s = p[i];
mini=a[i];
maxi=a[i];
}
}
cout << s-maxi+mini;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |