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 int long long
int n;
pair<int,int> a[500005];
int sp[500005];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i].first >> a[i].second;
sort(a + 1,a + n + 1);
for (int i = 1; i <= n; i++)
sp[i] = sp[i - 1] + a[i].second;
int ans = 0,mx = 0;
for (int i = 1; i <= n; i++)
{
///basically asta are size maxim, vreau sa maximizez sp[i] - sp[j - 1] + size[j] -> caut cea cu size[j] - sp[j - 1] maxima
mx = max(mx,a[i].first - sp[i - 1]);
ans = max(ans,sp[i] + mx - a[i].first);
}
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... |