結果

問題 No.54 Happy Hallowe'en
ユーザー simansiman
提出日時 2022-02-21 18:08:19
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 1,152 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 106,572 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 09:25:55
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 75 ms
4,376 KB
testcase_05 AC 110 ms
4,376 KB
testcase_06 AC 145 ms
4,380 KB
testcase_07 AC 190 ms
4,376 KB
testcase_08 AC 228 ms
4,380 KB
testcase_09 AC 270 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 157 ms
4,380 KB
testcase_13 AC 268 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Candy {
  int v;
  int t;

  Candy(int v = -1, int t = -1) {
    this->v = v;
    this->t = t;
  }

  bool operator<(const Candy &n) const {
    return v + t < (n.v + n.t);
  }
};

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
  }

  vector<Candy> candy_list;
  for (int i = 0; i < N; ++i) {
    int v, t;
    cin >> v >> t;

    candy_list.push_back(Candy(v, t));
  }

  sort(candy_list.begin(), candy_list.end());
  int dp[10010];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  int ans = 0;

  for (int i = 0; i < candy_list.size(); ++i) {
    Candy candy = candy_list[i];

    for (int v = 10000; v >= 0; --v) {
      if (dp[v] == -1) continue;

      int nv = v + candy.v;
      int cnt = candy.v;
      if (v >= candy.t) cnt = 1;
      nv = min(nv, 10000);

      dp[nv] = max(dp[nv], dp[v] + cnt);
      ans = max(ans, dp[nv]);
    }
  }

  cout << ans << endl;

  return 0;
}
0