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 ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
const int maxn = 5010;
const ll inf = 0x3f3f3f3f3f3f3f;
ll p[maxn];
ii v[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i].ff >> v[i].ss;
sort(v+1, v+1+n);
for (int i = 1; i <= n; i++) p[i] = p[i-1] + v[i].ss;
ll ans = -inf;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
ans = max(ans, p[j]-p[i-1]-v[j].ff+v[i].ff);
}
}
cout << ans << "\n";
}
# | 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... |