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 forin(i, a, b) for(int i = a; i <= b; i++)
#define forde(i, a, b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define ll long long
using namespace std;
const int N = 5e5 + 10;
pair<ll,ll> a[N];
ll res, s[N];
int main()
{
int n; cin >> n;
forin(i, 1, n) cin >> a[i].fi >> a[i].se;
sort(a+1, a+n+1);
forin(i, 1, n) s[i] = s[i-1] + a[i].se;
ll mini = s[0] - a[1].fi;
forin(i, 2, n)
{
mini = min(mini, s[i-1] - a[i].fi);
res = max(res, s[i] - a[i].fi -mini);
}
cout << res;
}
# | 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... |