Submission #66787154


Source Code Expand

// 綺麗に解きなおし

#include <bits/stdc++.h>
using namespace std;

/////////////////// メイン ///////////////////

int main () {
  
  //////////////////// 入力 ////////////////////

  int n, h, m;
  cin >> n >> h >> m;

  vector<int> a(n), b(n);
  for (int i=0; i<n; i++) {
    cin >> a.at(i) >> b.at(i);
  }

  //////////////// 出力変数定義 ////////////////

  int result = 0;

  //////////////////// 処理 ////////////////////

  // 動的計画法用の二次元vector
  // dp.at(i).at(j)は、i体のモンスターを倒すのに、体力がjあったら魔力はいくつ必要か
  vector<vector<int>> dp(n+1,vector<int>(h+1,0));

  // i体目までモンスターを倒している状態で次がどうなるか
  for (int i=0; i<n; i++) {

    // 体力がjである場合にどうなるか
    for (int j=0; j<=h; j++) {

      // 次のモンスターを体力消費で倒す場合
      int next1;
      if (j>=a.at(i)) next1 = dp.at(i).at(j-a.at(i));
      else next1 = 1e9;

      // 次のモンスターを魔力消費で倒す場合
      int next2 = dp.at(i).at(j) + b.at(i);

      // 2つのうち小さい方がそこの値
      dp.at(i+1).at(j) = min(next1,next2);

    }

  }

  // 魔力m以下で倒せる限界数を探す
  for (int i=n; i>=0; i--) {
    if (dp.at(i).back()<=m) {
      result = i;
      break;
    }
  }

  //////////////////// 出力 ////////////////////

  cout << result << endl;

  //////////////////// 終了 ////////////////////

  return 0;

}

Submission Info

Submission Time
Task E - Battles in a Row
User wightou
Language C++ 23 (gcc 12.2)
Score 450
Code Size 1583 Byte
Status AC
Exec Time 39 ms
Memory 38708 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 40
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 22 ms 22144 KiB
random_02.txt AC 24 ms 24992 KiB
random_03.txt AC 15 ms 15824 KiB
random_04.txt AC 8 ms 10080 KiB
random_05.txt AC 12 ms 13728 KiB
random_06.txt AC 6 ms 8416 KiB
random_07.txt AC 23 ms 23500 KiB
random_08.txt AC 27 ms 27728 KiB
random_09.txt AC 16 ms 17684 KiB
random_10.txt AC 13 ms 14492 KiB
random_11.txt AC 23 ms 24204 KiB
random_12.txt AC 15 ms 16580 KiB
random_13.txt AC 3 ms 5196 KiB
random_14.txt AC 8 ms 10028 KiB
random_15.txt AC 30 ms 30148 KiB
random_16.txt AC 12 ms 12916 KiB
random_17.txt AC 9 ms 10028 KiB
random_18.txt AC 8 ms 9476 KiB
random_19.txt AC 14 ms 15568 KiB
random_20.txt AC 15 ms 16340 KiB
random_21.txt AC 14 ms 16416 KiB
random_22.txt AC 7 ms 9816 KiB
random_23.txt AC 9 ms 11592 KiB
random_24.txt AC 14 ms 15568 KiB
random_25.txt AC 1 ms 3500 KiB
random_26.txt AC 1 ms 3500 KiB
random_27.txt AC 2 ms 4192 KiB
random_28.txt AC 1 ms 3480 KiB
random_29.txt AC 1 ms 3556 KiB
random_30.txt AC 1 ms 3584 KiB
random_31.txt AC 39 ms 38708 KiB
random_32.txt AC 33 ms 38456 KiB
random_33.txt AC 39 ms 38516 KiB
random_34.txt AC 39 ms 38520 KiB
random_35.txt AC 39 ms 38536 KiB
random_36.txt AC 38 ms 38456 KiB
random_37.txt AC 37 ms 38532 KiB
sample_01.txt AC 1 ms 3560 KiB
sample_02.txt AC 1 ms 3732 KiB
sample_03.txt AC 1 ms 3472 KiB