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<memory.h>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int lld;
lld n, s[500001] = {0, }, d[500001] = {0, }, a, b, tmp;
vector<pair<lld, lld>> art;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
art.push_back(pair<lld, lld>(0, 0));
for(int i = 0; i < n; i++) {
cin >> a >> b;
art.push_back(pair<lld, lld>(a, b));
}
d[0] = -9223372036854775808;
sort(art.begin(), art.end());
for(int i = 1; i <= n; i++) {
s[i] = s[i-1] + get<1>(art[i]);
d[i] = max(d[i-1], -s[i-1] + get<0>(art[i]));
}
lld tmp = 0;
for(int i = 1; i <= n; i++) {
tmp = max(tmp, s[i] - get<0>(art[i]) + d[i]);
}
cout << tmp;
return 0;
}
Compilation message (stderr)
art.cpp:23:13: warning: integer constant is so large that it is unsigned
d[0] = -9223372036854775808;
^~~~~~~~~~~~~~~~~~~
# | 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... |