이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
/*
pref[j] - pref[i - 1] >= x[j] - x[i]
pref[j] - x[j] >= pref[i - 1] - x[i]
*/
const int N=101000;
int n,x[N],g[N],d[N];
ll pf[N],tot[N],dp[N];
struct node{
ll mn;
node(){ mn=1e16; }
}nd[4*N];
void upd(int p) {
nd[p].mn=min(nd[p*2].mn,nd[p*2+1].mn);
}
void modify(int p,int l,int r,int tl,ll x) {
if (l==r) nd[p].mn=min(nd[p].mn,x);
else {
int md=(l+r)>>1;
if (tl<=md) modify(p*2,l,md,tl,x);
else modify(p*2+1,md+1,r,tl,x);
upd(p);
}
}
ll get(int p,int l,int r,int tl,int tr) {
if (l>tr||r<tl) return 1e18;
if (tl<=l&&r<=tr) return nd[p].mn;
int md=(l+r)>>1;
return min(get(p*2,l,md,tl,tr),get(p*2+1,md+1,r,tl,tr));
}
int main() {
scanf("%d",&n);
rep(i,1,n+1) scanf("%d%d%d",x+i,g+i,d+i);
rep(i,1,n+1) pf[i]=pf[i-1]+d[i];
rep(i,1,n+1) tot[i]=tot[i-1]+g[i];
// rep(i,1,n+1) printf("%lld ",tot[i]); puts("");
vector<ll> c;
rep(i,1,n+1) c.pb(pf[i]-x[i]),c.pb(pf[i-1]-x[i]);
sort(all(c)); c.erase(unique(all(c)),c.end());
auto val=[&](ll i) {
return lower_bound(all(c),i)-c.begin();
};
rep(i,1,n+1) {
modify(1,0,SZ(c)-1,val(pf[i-1]-x[i]),tot[i-1]);
dp[i]=tot[i]-get(1,0,SZ(c)-1,0,val(pf[i]-x[i]));
}
ll ans=0;
rep(i,1,n+1) ans=max(ans,dp[i]);
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
divide.cpp: In function 'int main()':
divide.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
divide.cpp:53:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | rep(i,1,n+1) scanf("%d%d%d",x+i,g+i,d+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |