이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define llinf 987654321987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
struct SEGMENT_TREE {
struct NODE {
int st, fin;
LL maxx;
} tree[3000000];
int x=0;
void maketree(int point, int num) {
if(num==1) {
x++;
tree[point].st=tree[point].fin=x;
}
if(num<=1)return;
maketree(point*2, num-num/2);
maketree(point*2+1, num/2);
tree[point].st=tree[point*2].st;
tree[point].fin=tree[point*2+1].fin;
}
LL maxrange(int a, int b, int point) {
if(tree[point].st>=a&&tree[point].fin<=b)return tree[point].maxx;
if(tree[point].st>b||tree[point].fin<a)return -llinf;
return max(maxrange(a, b, point*2), maxrange(a, b, point*2+1));
}
void updaterange(int point, int num, LL p) {
if(tree[point].st==tree[point].fin) {
tree[point].maxx=p;
return;
}
if(num<=tree[point*2].fin)updaterange(point*2, num, p);
else updaterange(point*2+1, num, p);
tree[point].maxx=max(tree[point*2].maxx, tree[point*2+1].maxx);
}
void init(int n) {
maketree(1, n);
}
LL get_max(int a, int b) {
return maxrange(a, b, 1);
}
void update(int a, LL num) {
updaterange(1, a, num);
}
}seg;
int n;
pll arr[500010];
LL sum[500010], ans;
int main()
{
scanf("%d", &n);
seg.init(n);
for(int i=1; i<=n; i++){
scanf("%lld %lld", &arr[i].F, &arr[i].S);
}
sort(arr+1, arr+n+1);
for(int i=1; i<=n; i++)
sum[i]=sum[i-1]+arr[i].S;
for(int i=1; i<=n; i++)
seg.update(i, sum[i]-arr[i].F);
for(int i=1; i<=n; i++)
ans=max(ans, seg.get_max(i, n)+arr[i].F-sum[i-1]);
printf("%lld", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
art.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &arr[i].F, &arr[i].S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |