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>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define down "\n"
#define ll long long
#define fi first
#define se second
#define fon(i, x, y) for(int i = (x), _y = (y); i <= _y; ++ i)
#define fol(i, x, y) for(int i = (x), _y = (y); i >= _y; -- i)
#define po 1000000000000000000
#define ne -1000000000000000000
#define ii pair<ll, ll>
using namespace std;
const ll int maxn = 1e6 + 10;
const ll int N = 1503;
// ▄▄▄▄ ▄▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄ ▄▄▄▄ ▄▄▄▄
// █▄▄█ ██ █ █▄▄█ █▄█ █▄▄█ █ █ █▄▄█
// █ █ █ ██ █ █ █ █ █ █ █▄▄█ █ █
ii a[maxn];
ll oo = 1e18;
ll n;
void inp(){
cin>>n;
fon(i, 1, n) cin>>a[i].fi>>a[i].se;
}
void solve(){
sort(a+1, a+n+1);
ll i2 = 1;
ll tong = 0;
ll kq = 0-oo;
fon(i, 1, n){
if(tong < a[i].fi-a[i2].fi){
tong = 0;
i2 = i;
}
tong = tong + a[i].se;
kq = max(kq, tong - (a[i].fi-a[i2].fi));
}
cout<<kq;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
inp();
solve();
}
/**/
| # | 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... |