結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー risujirohrisujiroh
提出日時 2019-12-14 00:26:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 174,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 07:57:08
合計ジャッジ時間 6,605 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 54 ms
4,380 KB
testcase_14 AC 11 ms
4,376 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 18 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 78 ms
4,376 KB
testcase_25 AC 79 ms
4,376 KB
testcase_26 AC 76 ms
4,380 KB
testcase_27 AC 77 ms
4,376 KB
testcase_28 AC 69 ms
4,380 KB
testcase_29 AC 70 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 78 ms
4,376 KB
testcase_36 AC 78 ms
4,376 KB
testcase_37 AC 78 ms
4,380 KB
testcase_38 AC 78 ms
4,380 KB
testcase_39 AC 77 ms
4,380 KB
testcase_40 AC 73 ms
4,376 KB
testcase_41 AC 74 ms
4,376 KB
testcase_42 AC 74 ms
4,376 KB
testcase_43 AC 73 ms
4,376 KB
testcase_44 AC 74 ms
4,380 KB
testcase_45 AC 74 ms
4,376 KB
testcase_46 AC 65 ms
4,376 KB
testcase_47 AC 66 ms
4,376 KB
testcase_48 AC 68 ms
4,380 KB
testcase_49 AC 67 ms
4,376 KB
testcase_50 AC 65 ms
4,376 KB
testcase_51 AC 66 ms
4,380 KB
testcase_52 AC 63 ms
4,376 KB
testcase_53 AC 76 ms
4,376 KB
testcase_54 AC 57 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> p(n), d(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i] >> d[i];
  }
  vector<int> idx(n);
  iota(begin(idx), end(idx), 0);
  sort(begin(idx), end(idx), [&](int i, int j) { 
    return p[i] > p[j]; 
  });
  auto chmax = [](auto&& l, auto r) { l = max(l, r); };
  vector< vector<int> > dp(2, vector<int>(k + 1, -1e9));
  dp[0][0] = 0;
  for (int i : idx) {
    auto ndp = dp;
    for (int x = 0; x <= k; ++x) {
      if (x + p[i] <= k) {
        chmax(ndp[1][x + p[i]], dp[0][x] + d[i]);
      }
      chmax(ndp[0][x], dp[1][x] + d[i]);
    }
    swap(dp, ndp);
  }
  int res = 0;
  for (auto v : dp) {
    chmax(res, *max_element(begin(v), end(v)));
  }
  cout << res << '\n';
}
0