이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define val first
#define ind second
using namespace std;
const int N=1e5+5;
int n,a,b,x;
ll ans;
typedef struct{
int x, gold , energy;
}camp;
vector<camp> v;
vector<pair<ll, int>> mn;
map <int, ll> g, d;
main(){
cin>>n;
for(int i=0; i<n; i++){
cin>>x>>a>>b;
v.push_back({x,a,b});
}
g[0]=v[0].gold; d[0]=v[0].energy;
for(int i=1; i<n; i++){
g[i]=g[i-1]+v[i].gold;
d[i]=d[i-1]+v[i].energy;
}
a=0;
for(int i=0; i<n; i++){
b=i; int mid=0;
int cost=d[b]-v[b].x;
if(mn.size()==0 || mn[mn.size()-1].val>d[b-1]-v[b].x){
mn.push_back({d[b-1]-v[b].x,i});
}
int l=0; int r=mn.size()-1;
while(l<=r){
mid=(l+r)/2;
if(mn[mid].val<=cost) r=mid-1;
else l=mid+1;
}
a=mn[mid].ind;
ans=max(ans, g[b]-g[a-1]);
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
divide.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
15 | main(){
| ^| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |