結果
問題 | No.409 ダイエット |
ユーザー |
![]() |
提出日時 | 2024-11-10 12:41:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 2,021 ms |
コンパイル使用メモリ | 166,408 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-11-10 12:41:18 |
合計ジャッジ時間 | 5,436 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 92 |
ソースコード
#include<bits/stdc++.h> using namespace std; int d[300005],q[300005]; long long f[300005]; int hd=1,tl=0; bool ok(int x,int y,int z){ return (__int128)(f[y]-f[x])*(z-y)>=(__int128)(f[z]-f[y])*(y-x); } bool test(int x,int y,long long z){ return f[y]-f[x]<=(__int128)(y-x)*z; } void add(int x){ while(tl>=hd+1&&ok(q[tl-1],q[tl],x))--tl; q[++tl]=x; } int main(){ int n,a,b,w; scanf("%d%d%d%d",&n,&a,&b,&w); for(int i=1;i<=n;++i)scanf("%d",&d[i]); memset(f,63,sizeof(f)); f[0]=w; for(int i=1;i<=n+1;++i){ long long sz=1ll*i*a+1ll*i*(i-1)/2*b; f[i-1]+=sz; add(i-1); while(tl>=hd+1&&test(q[hd],q[hd+1],1ll*i*b))++hd; int j=q[hd];f[i]=f[j]-1ll*i*j*b; long long zs=d[i]-1ll*i*a+1ll*i*(i-1)/2*b; f[i]+=zs; } printf("%lld\n",f[n+1]); return 0; }