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;
const int N = 5e5;
pair<long long,long long> p[N+5];
int n;
int main(){
cin >> n;
for(int i = 0; i < n; i++)cin >> p[i].first >> p[i].second;
sort(p,p+n);
for(int i = n-1; i > 0; i--){
if(p[i].first == p[i-1].first){
p[i-1].second += p[i].second;
p[i].second = 0;
}
}
long long tong = p[0].second;
long long a = p[0].first;
long long res = tong;
for(int i = 1; i < n; i++){
tong+= p[i].second;
if(tong <= p[i].first - a){
tong = p[i].second;
a = p[i].first;
}
res = max(res, tong - p[i].first + a);
}
cout << res;
}
| # | 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... |