이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
struct ceva {
long long sz, val;
} v[500002];
bool cmp(ceva x, ceva y) {
return x.sz < y.sz;
}
int n;
long long sp[500002], tree[2000005];
void build(int node, int st, int dr) {
if (st == dr) {
tree[node] = sp[st] - v[st].sz;
return ;
}
int mij = (st + dr)/2;
build(2*node, st, mij);
build(2*node+1, mij+1, dr);
tree[node] = max(tree[2*node], tree[2*node+1]);
}
int query(int node, int st, int dr, int left, int right) {
if (left <= st and dr <= right) {
return tree[node];
}
int mij = (st + dr)/2;
long long ans1 = LLONG_MIN, ans2 = LLONG_MIN;
if (left <= mij)
ans1 = query(2*node, st, mij, left, right);
if (mij < right)
ans2 = query(2*node+1, mij+1, dr, left, right);
return max(ans1, ans2);
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i].sz >> v[i].val;
}
sort(v+1, v+n+1, cmp);
for (int i = 1; i <= n; i++) {
sp[i] = sp[i-1] + v[i].val;
}
build(1, 1, n);
long long maxim = LLONG_MIN;
for (int i = 1; i <= n; i++) {
long long x = sp[i-1] - v[i].sz;
long long rezdr = query(1, 1, n, i, n);
maxim = max(maxim, rezdr-x);
}
cout << maxim;
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... |