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 int long long
using namespace std;
const int N = 5e5 + 10;
int n , a[N] , b[N] , ps[N];
pair<int , int> ar[N];
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; i++)
cin >> ar[i].first >> ar[i].second;
sort(ar , ar + n);
for(int i = 0 ; i < n ; i++)
{
a[i] = ar[i].first; b[i] = ar[i].second;
ps[i] = b[i] + (i == 0 ? 0 : ps[i - 1]);
}
int ans = 0;
int mx = -1e15;
for(int i = n - 1 ; i > -1 ; i--)
{
mx = max(mx , ps[i] - a[i]);
ans = max(ans , mx - (i == 0 ? 0 : ps[i - 1]) + a[i]);
}
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... |