問題一覧 > 通常問題

No.409 Diet

レベル : / AI推定難易度 : 2150 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 94
作問者 : btk / テスター : ciel
お気に入りにしたユーザー ProblemId : 1064 / 自分の提出
問題文最終更新日: 2026-06-25 04:04:12
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 145 (順位表) の他の問題:

Problem Statement

btk eats donuts every day.
One day, btk decided to go on a diet for N days.
btk buys donuts at a different shop each day, and it is known that eating a donut from the shop visited on day i of the diet increases btk's weight by $D_i$kg. Also, by skipping donuts for 1 day, btk can lose $A$kg.

However, consecutive days without donuts build up stress. Here, we define a parameter called the stress value. The stress value at the start of the diet is 0.
For each 1 day without eating a donut, the stress value increases by 1, and at the end of that day btk's weight increases by $B*(ストレス値)$kg, where ストレス値 denotes the stress value. Eating a donut resets the stress value to 0.

Note that on each day, the weight changes after the stress value changes.

Given that btk's weight before the start of the diet is $W$ kg, how many kg can btk slim down to over the N days?

Input

$N$ $A$ $B$ $W$
$D_1$ $D_2$ ... $D_{N}$

$1 \le N \le 3*10^5$
$0 \le A,B,W \le 10^6$
$0 \le D_i \le 10^6$

Output

Print on one line the minimum possible weight of btk after the end of day N.
The final weight may be negative.

Sample

Sample 1
Input
2 5 2 10
0 6
Output
6

If btk eats donuts on both days:
$10 + (0) + (6) = 16$
If btk eats a donut only on day 1:
$10 + (0) + (-5 + 2×1)=7$
If btk eats a donut only on day 2:
$10 + (-5 + 2×1) + (6) = 13$
If btk eats no donuts on either day:
$10 + (-5 + 2×1) + (-5 + 2×2) = 6$

Therefore, eating no donuts on either day is optimal, and the answer is 6.

Sample 2
Input
5 1 0 50
1 2 3 4 5
Output
45

btk does not gain weight from stress, so fasting for all 5 days is optimal.

Sample 3
Input
7 4 6 56
10 9 7 17 8 3 7
Output
88

No matter how hard btk tries, the weight will never go down (tears of blood).

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。