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
#define f(i, a, b) for(int i = a; i <= b; i++)
#define fr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define in insert
#define vvec vector<vector<int>>
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 5e5 + 5;
int n, k, f[N];
pii a[N];
vector <int> z;
void sub1()
{
int res = 0;
f(i, 1, n)
{
int s = 0, mn = 1e17, mx = 0;
f(j, i, n)
{
s += a[j].se;
mn = min(mn, a[j].fi);
mx = max(mx, a[j].fi);
res = max(res, s - (mx - mn));
}
}
cout << res;
}
void sub2()
{
int mn = a[1].fi, res = 0;
f(i, 1, n) f[i] = f[i - 1] + a[i].se;
f(i, 1, n)
{
//cout << a[i].fi << " " << a[i].se << "\n";
//cout << f[i] << " " << mn << "\n";
res = max(res, f[i] + a[i].fi - mn);
mn = min(mn, f[i] + a[i + 1].fi);
}
cout << res;
}
signed main()
{
fast;
cin >> n;
f(i, 1, n) cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1, greater <pii> {});
//sub1();
sub2();
}
# | 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... |