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;
int main()
{
//freopen("i.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
typedef pair<long long, long long> ii;
ii arr[n];
for(int i = 0;i < n;i++){
cin >> arr[i].first >> arr[i].second;
}
sort(arr,arr+n);
long long pre[n];
pre[0] = arr[0].second;
for(int i = 1;i < n;i++){
pre[i] = pre[i-1] + arr[i].second;
}
long long maxv = 0ll;
long long ans = 0ll;
for(int i = 0;i < n;i++){
ans = max(ans, arr[i].second);
ans = max(pre[i] - arr[i].first + maxv, ans);
long long v = arr[i].first;
if(i != 0) v -= pre[i-1];
maxv = max(maxv, v);
}
cout << ans;
return 0;
}
# | 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... |