#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll i, j, ans, tem, n;
bool cmp(pair<ll, ll> a, pair<ll, ll> b){
return a.first < b.first;
}
void run(){
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
// int tt; cin >> tt; while(tt--) run();
cin >> n; pair<ll, ll> p[n+1];
for( i = 1; i <= n; i++) cin >> p[i].first >> p[i].second;
sort(p+1, p+n+1, cmp); p[0].second = 0;
for( i = 1; i <= n; i++) p[i].second += p[i-1].second;
j = p[1].first-p[0].second;
for( i = 1; i <= n; i++){
j = max(j, p[i].first-p[i-1].second);
ans = max(ans, -p[i].first+p[i].second+j);
} cout << ans << '\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... |