이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
using namespace std;
const int mxn=5e5+5;
const ll inf=1e18;
struct segtree {
ll tree[4*mxn];
void init() {
for(int i=1;i<4*mxn;i++) tree[i]=-inf;
}
void update(int node,int b,int e,int p,ll v) {
if(e<p || b>p)return;
if(b==e) {
tree[node]=v;
return;
}
int mid=b+e>>1;
int left=node<<1;
int right=left|1;
update(left,b,mid,p,v);
update(right,mid+1,e,p,v);
tree[node]=max(tree[left],tree[right]);
}
} st;
int main() {
int n;
cin>>n;
pii a[n];
for(int i=0;i<n;i++) {
scanf("%lld %lld",&a[i].first,&a[i].second);
}
sort(a,a+n);
reverse(a,a+n);
st.init();
ll ps=0;
for(int i=0;i<n;i++) {
ps+=a[i].second;
st.update(1,1,n,i+1,ps+a[i].first);
}
ps=0;
ll ans=-inf;
for(int i=0;i<n;i++) {
ll v=st.tree[1];
v-=ps+a[i].first;
ans=max(ans,v);
st.update(1,1,n,i+1,-inf);
ps+=a[i].second;
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In member function 'void segtree::update(int, int, int, int, long long int)':
art.cpp:21:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | int mid=b+e>>1;
| ~^~
art.cpp: In function 'int main()':
art.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
38 | scanf("%lld %lld",&a[i].first,&a[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |