結果
問題 |
No.409 ダイエット
|
ユーザー |
![]() |
提出日時 | 2024-11-12 18:49:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,160 bytes |
コンパイル時間 | 1,999 ms |
コンパイル使用メモリ | 167,980 KB |
実行使用メモリ | 31,232 KB |
最終ジャッジ日時 | 2024-11-12 18:49:38 |
合計ジャッジ時間 | 6,584 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 91 WA * 1 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; inline int read() { register int x=0,f=0;register char c=getchar(); while(c<'0'||c>'9')f=(c=='-'),c=getchar(); while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c&15),c=getchar(); return f?-x:x; } const int MAXN=3e6; int n,a,b,w,d[MAXN],dp[MAXN]; long double Y(int i){ return (long double)(dp[i]+i*a+1.0*b*(i*i+i)/2); } long double X(int i){ return (long double)1.0*i; } long double K(int j1,int j2){ return (long double)1.0*(Y(j1)-Y(j2))/(X(j1)-X(j2)); } int q[MAXN],head,tail; signed main() { // freopen("chips.in","r",stdin); // freopen("chips.out","w",stdout); memset(dp,0x3f,sizeof dp); n=read();a=read();b=read();w=read(); for(int i=1;i<=n;i++)d[i]=read(); dp[0]=w; head=1;tail=1;q[1]=0; for(int i=1;i<=n;i++){ while(head<tail && (long double)K(q[head],q[head+1])<=(long double)1.0*i*b)head++; int j=q[head]; dp[i]=dp[j]-(i-j-1)*a+d[i]+b*(i-j-1)*(i-j)/2; while(head<tail && (long double)K(q[tail],i)<=(long double)K(q[tail],q[tail-1]) )tail--; q[++tail]=i; } int ans=1e18; for(int i=n;i>=0;i--){ ans=min(ans,dp[i]-(n-i)*a+b*(n-i+1)*(n-i)/2); } cout<<ans; return 0; }