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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;
#define fs first
#define sc second
pair<ll, ll> arr[500005];
ll n;
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
return a.first < b.first;
}
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i].first >> arr[i].second;
}
sort(arr + 1, arr + n + 1, cmp);
pair<ll, ll> tmp;
ll ans = 0;
for (int i = 1; i <= n; ++i) {
tmp = { 0, 0 };
for (int j = i; j <= n; ++j) {
tmp.fs = arr[j].fs;
tmp.sc += arr[j].sc;
ans = max(ans, tmp.sc - tmp.fs + arr[i].fs);
}
}
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... |