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>
#define ll long long
#define pb push_back
#define s second
#define f first
#define pll pair <ll,ll>
#define pii pair <int,int>
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
using namespace std;
const int N = 5e5 + 5;
ll t[4*N],lz[4*N],p[N];
pll d[N];
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++){
cin>>d[i].f>>d[i].s;
}
sort(d + 1,d + n + 1);
for (int i = 1; i <= n; i++){
p[i] = p[i - 1] + d[i].s;
}
ll ans = 0,mn = 1e18;
for (int i = 0; i <= n; i++){
ans = max(ans, p[i] - d[i].f - mn);
mn = min(mn, p[i] - d[i + 1].f);
}
cout<<ans;
}
# | 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... |