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;
forin(i, 1, n-1)
{
forin(j, i+1,n)
{
res = max(res, s[j] - s[i-1] - a[j].fi + a[i].fi);
}
}
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... |