結果

問題 No.409 ダイエット
ユーザー 🐬hec🐬hec
提出日時 2016-08-09 15:25:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 164,836 KB
実行使用メモリ 13,896 KB
最終ジャッジ日時 2023-09-08 16:59:59
合計ジャッジ時間 5,800 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,604 KB
testcase_01 AC 3 ms
9,880 KB
testcase_02 AC 3 ms
9,812 KB
testcase_03 AC 3 ms
9,688 KB
testcase_04 AC 2 ms
9,684 KB
testcase_05 AC 2 ms
9,684 KB
testcase_06 AC 3 ms
9,684 KB
testcase_07 AC 3 ms
9,604 KB
testcase_08 AC 3 ms
9,660 KB
testcase_09 AC 2 ms
9,684 KB
testcase_10 AC 3 ms
9,752 KB
testcase_11 AC 2 ms
9,664 KB
testcase_12 AC 3 ms
9,732 KB
testcase_13 AC 2 ms
9,672 KB
testcase_14 AC 3 ms
9,744 KB
testcase_15 AC 3 ms
9,700 KB
testcase_16 AC 3 ms
9,676 KB
testcase_17 AC 3 ms
9,684 KB
testcase_18 AC 3 ms
9,740 KB
testcase_19 AC 3 ms
9,680 KB
testcase_20 AC 3 ms
9,604 KB
testcase_21 AC 2 ms
9,676 KB
testcase_22 AC 3 ms
9,672 KB
testcase_23 AC 2 ms
9,672 KB
testcase_24 AC 2 ms
9,684 KB
testcase_25 AC 2 ms
9,872 KB
testcase_26 AC 3 ms
9,608 KB
testcase_27 AC 3 ms
9,660 KB
testcase_28 AC 3 ms
9,680 KB
testcase_29 AC 3 ms
9,740 KB
testcase_30 AC 3 ms
9,684 KB
testcase_31 AC 2 ms
9,604 KB
testcase_32 AC 3 ms
9,616 KB
testcase_33 AC 2 ms
9,616 KB
testcase_34 AC 3 ms
9,668 KB
testcase_35 AC 3 ms
9,620 KB
testcase_36 AC 3 ms
9,696 KB
testcase_37 AC 4 ms
9,760 KB
testcase_38 AC 3 ms
9,760 KB
testcase_39 AC 3 ms
9,700 KB
testcase_40 AC 3 ms
9,776 KB
testcase_41 AC 3 ms
9,632 KB
testcase_42 AC 3 ms
9,700 KB
testcase_43 AC 3 ms
9,708 KB
testcase_44 AC 3 ms
9,680 KB
testcase_45 AC 3 ms
9,708 KB
testcase_46 AC 3 ms
9,888 KB
testcase_47 AC 3 ms
9,648 KB
testcase_48 AC 3 ms
9,896 KB
testcase_49 AC 3 ms
9,712 KB
testcase_50 AC 3 ms
9,700 KB
testcase_51 AC 3 ms
9,740 KB
testcase_52 AC 3 ms
9,712 KB
testcase_53 AC 3 ms
9,732 KB
testcase_54 AC 3 ms
9,724 KB
testcase_55 AC 17 ms
13,024 KB
testcase_56 AC 28 ms
13,016 KB
testcase_57 AC 31 ms
13,896 KB
testcase_58 AC 15 ms
13,008 KB
testcase_59 AC 21 ms
12,960 KB
testcase_60 AC 14 ms
12,868 KB
testcase_61 AC 28 ms
13,312 KB
testcase_62 AC 29 ms
13,628 KB
testcase_63 AC 27 ms
13,244 KB
testcase_64 AC 17 ms
12,940 KB
testcase_65 AC 29 ms
13,056 KB
testcase_66 AC 31 ms
13,644 KB
testcase_67 AC 23 ms
13,360 KB
testcase_68 AC 21 ms
12,952 KB
testcase_69 AC 28 ms
13,244 KB
testcase_70 AC 33 ms
13,336 KB
testcase_71 AC 19 ms
13,032 KB
testcase_72 AC 38 ms
13,704 KB
testcase_73 AC 36 ms
13,152 KB
testcase_74 AC 24 ms
13,312 KB
testcase_75 AC 36 ms
13,184 KB
testcase_76 AC 26 ms
13,468 KB
testcase_77 AC 19 ms
12,824 KB
testcase_78 AC 21 ms
13,180 KB
testcase_79 AC 18 ms
12,928 KB
testcase_80 AC 37 ms
13,516 KB
testcase_81 AC 36 ms
13,388 KB
testcase_82 AC 27 ms
13,212 KB
testcase_83 AC 30 ms
13,152 KB
testcase_84 AC 25 ms
12,900 KB
testcase_85 AC 5 ms
9,816 KB
testcase_86 AC 25 ms
12,940 KB
testcase_87 AC 32 ms
13,300 KB
testcase_88 AC 15 ms
12,612 KB
testcase_89 AC 29 ms
12,764 KB
testcase_90 AC 14 ms
12,496 KB
testcase_91 AC 30 ms
12,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;
using ll=long long;
const ll inf=1LL<<58;

ll d[300010];
ll ca[300010],cb[300010];
ll dp[300010];

int deq[300010];

inline bool check(int i,int j,int k){ return (ca[j]-ca[i])*(cb[k]-cb[j])>= (cb[j]-cb[i])*(ca[k]-ca[j]);}
inline ll f(int idx,ll i){ return ca[idx]*i+cb[idx];}

int main(void){
	ll n,a,b,w;
	scanf("%lld %lld %lld %lld",&n,&a,&b,&w);
	rep(i,n) scanf("%lld",d+i);

	dp[0]=w,ca[0]=0,cb[0]=dp[0],deq[0]=0;
	int s=0,t=1;

	rep(i,1,n+1){
		while(t-s>=2 && f(deq[s],i) >= f(deq[s+1],i)) s++;
		dp[i]=d[i-1]-1LL*(i-1)*a+1LL*(i-1)*i/2*b+f(deq[s],i);		
		ca[i]=-1LL*b*i,cb[i]=dp[i]+1LL*i*a+1LL*i*(i+1)/2*b;
		while(t-s>=2 && check(deq[t-2],deq[t-1],i)) t--;
		deq[t++]=i;
	}

	ll ans=inf;
	rep(i,n+1){
	    ll e=n-i;
        chmin(ans,dp[i]-a*e+b*e*(e+1)/2);
    }
    printf("%lld\n",ans);
    return 0;
}
0