이 제출은 이전 버전의 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 a[MXN];
int pre[MXN];
priority_queue<pii> pq;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].sz >> a[i].val;
}
sort(a, a + 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] + a[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;
for (int j = 1; j <= n; j++) pq.push({pre[j] - a[j - 1].sz, j});
for (int i = 0; i < n; i++) {
while (pq.top().second <= i) pq.pop();
ans = max(ans, a[i].sz - pre[i] + pq.top().first);
}
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... |