結果

問題 No.409 ダイエット
ユーザー 0w10w1
提出日時 2019-11-26 12:13:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 68,652 KB
実行使用メモリ 6,752 KB
最終ジャッジ日時 2023-08-06 13:11:10
合計ジャッジ時間 5,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 3 ms
4,376 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 3 ms
4,380 KB
testcase_47 AC 3 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 3 ms
4,380 KB
testcase_50 AC 3 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 3 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 27 ms
5,068 KB
testcase_56 AC 46 ms
4,448 KB
testcase_57 AC 55 ms
6,752 KB
testcase_58 AC 24 ms
4,816 KB
testcase_59 AC 35 ms
5,420 KB
testcase_60 AC 22 ms
4,796 KB
testcase_61 AC 48 ms
6,392 KB
testcase_62 AC 52 ms
6,592 KB
testcase_63 AC 48 ms
6,364 KB
testcase_64 AC 26 ms
4,904 KB
testcase_65 AC 53 ms
6,428 KB
testcase_66 AC 54 ms
6,736 KB
testcase_67 AC 40 ms
5,940 KB
testcase_68 AC 34 ms
5,512 KB
testcase_69 AC 47 ms
6,304 KB
testcase_70 AC 72 ms
6,088 KB
testcase_71 AC 40 ms
4,860 KB
testcase_72 AC 86 ms
6,684 KB
testcase_73 AC 81 ms
6,400 KB
testcase_74 AC 51 ms
5,252 KB
testcase_75 AC 82 ms
6,440 KB
testcase_76 AC 59 ms
5,632 KB
testcase_77 AC 40 ms
4,840 KB
testcase_78 AC 45 ms
5,068 KB
testcase_79 AC 36 ms
4,828 KB
testcase_80 AC 83 ms
6,668 KB
testcase_81 AC 80 ms
6,660 KB
testcase_82 AC 60 ms
5,668 KB
testcase_83 AC 64 ms
5,952 KB
testcase_84 AC 53 ms
5,312 KB
testcase_85 AC 7 ms
4,380 KB
testcase_86 AC 52 ms
5,284 KB
testcase_87 AC 71 ms
6,084 KB
testcase_88 AC 30 ms
4,620 KB
testcase_89 AC 74 ms
5,640 KB
testcase_90 AC 30 ms
4,380 KB
testcase_91 AC 79 ms
5,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

long long find_min(int, long long *);
long long int n, a, b, w;
int temp = 0, brk = 0;

int main() {
  // input
  cin >> n >> a >> b >> w;

  int *D = new int[n];
  for (int i = 0; i < n; i++) cin >> D[i];

  // output when b = 0
  if (b == 0) {
    cout << w - a * n << endl;
    return 0;
  }

  long long *zero = new long long[n + 1];
  zero[0] = 0;

  for (int i = 0; i < n; i++) zero[i + 1] = find_min(i, zero) + D[i];
  cout << w + find_min(n, zero) << endl;
}

long long find_min(int i, long long *zero) {
  if (i <= 0) return 0;
  long long min = zero[i], total;  // *zero DISP -- 1
  for (int k = 1; k <= i; k++) {
    total = zero[i - k] - a * k + b * (1 + k) * k / 2;
    if (total < min) min = total, brk = i - k;
    if (i - k < temp) break;
  }
  temp = brk;
  return min;
}
0