이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
struct P {
int sz, val;
P() {
sz = 0;
val = 0;
}
P(int _sz, int _val) {
sz = _sz;
val = _val;
}
};
const int MXN = 500005;
int n, ans = 0;
P art[MXN];
int pre[MXN];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> art[i].sz >> art[i].val;
}
sort(art, art + n, [](P &a, P &b) {
return (a.sz == b.sz ? a.val < b.val : a.sz < b.sz);
});
for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + art[i].val;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
ans = max(ans, pre[j] - pre[i] - (art[j - 1].sz - art[i].sz));
}
}
cout << ans << endl;
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... |