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;
#define ll long long
#define pb push_back
#define ull unsigned long long
#define fi first
#define se second
#define ld long double
ll n, pref[500005];
pair<ll, ll>arr[500005];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
for(int i=1;i<=n;++i){
cin >> arr[i].fi >> arr[i].se;
}
sort(arr+1, arr+1+n);
for(int i=1;i<=n;++i) pref[i]=pref[i-1]+arr[i].se;
ll l=1, maks=0;
for(int i=1;i<=n;++i){
while((pref[i]-pref[l-1])-(arr[i].fi-arr[l].fi) < 0){
++l;
}
maks=max(maks, (pref[i]-pref[l-1])-(arr[i].fi-arr[l].fi));
}
cout << maks << '\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... |