結果
問題 | No.409 ダイエット |
ユーザー |
![]() |
提出日時 | 2024-11-13 08:20:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 961 bytes |
コンパイル時間 | 2,073 ms |
コンパイル使用メモリ | 168,036 KB |
実行使用メモリ | 10,240 KB |
最終ジャッジ日時 | 2024-11-13 08:21:03 |
合計ジャッジ時間 | 5,053 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 92 |
ソースコード
#include<bits/stdc++.h> #define il inline #define ll long long #define lb long double using namespace std; il ll read(){ ll a=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();} while(ch>='0'&&ch<='9'){a=a*10+ch-'0';ch=getchar();} return a*f; } ll n,A,B,f[300010],ruby[300010],ans=1e18,q[300010],head,tail; ll Y(ll x){ return f[x]+A*x+(x+1)*x/2*B; } lb K(ll x,ll y){ return (lb)1.0*(Y(x)-Y(y))/(x-y); } int main(){ // freopen("chips.in","r",stdin); // freopen("chips.out","w",stdout); memset(f,0x3f,sizeof f); n=read();A=read();B=read();f[0]=read(); q[1]=0;head=1;tail=1; for(int i=1;i<=n;++i){ ruby[i]=read(); while(head<tail&&K(q[head],q[head+1])<=i*B)++head; f[i]=min(f[i],f[q[head]]+ruby[i]-A*(i-q[head]-1)+(i-q[head])*(i-q[head]-1)*B/2); while(head<tail&&K(q[tail],i)<=K(q[tail-1],q[tail]))--tail; q[++tail]=i; } for(int i=0;i<=n;++i) ans=min(ans,f[i]-A*(n-i)+(n-i+1)*(n-i)*B/2); cout<<ans; return 0; }