結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー iqueue02iqueue02
提出日時 2019-12-15 13:47:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,529 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 2,379 ms
コンパイル使用メモリ 180,796 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 15:37:03
合計ジャッジ時間 44,965 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 34 ms
4,376 KB
testcase_10 AC 20 ms
4,384 KB
testcase_11 AC 20 ms
4,380 KB
testcase_12 AC 291 ms
4,380 KB
testcase_13 AC 978 ms
4,380 KB
testcase_14 AC 168 ms
4,376 KB
testcase_15 AC 172 ms
4,376 KB
testcase_16 AC 258 ms
4,384 KB
testcase_17 AC 319 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 19 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 1,518 ms
4,380 KB
testcase_25 AC 1,521 ms
4,380 KB
testcase_26 AC 1,521 ms
4,380 KB
testcase_27 AC 1,520 ms
4,376 KB
testcase_28 AC 1,514 ms
4,380 KB
testcase_29 AC 1,517 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 9 ms
4,380 KB
testcase_33 AC 14 ms
4,380 KB
testcase_34 AC 31 ms
4,376 KB
testcase_35 AC 1,516 ms
4,376 KB
testcase_36 AC 1,517 ms
4,380 KB
testcase_37 AC 1,516 ms
4,380 KB
testcase_38 AC 1,515 ms
4,376 KB
testcase_39 AC 1,513 ms
4,376 KB
testcase_40 AC 1,515 ms
4,376 KB
testcase_41 AC 1,520 ms
4,384 KB
testcase_42 AC 1,519 ms
4,380 KB
testcase_43 AC 1,529 ms
4,380 KB
testcase_44 AC 1,521 ms
4,380 KB
testcase_45 AC 1,528 ms
4,380 KB
testcase_46 AC 1,513 ms
4,376 KB
testcase_47 AC 1,514 ms
4,380 KB
testcase_48 AC 1,518 ms
4,380 KB
testcase_49 AC 1,516 ms
4,376 KB
testcase_50 AC 1,518 ms
4,380 KB
testcase_51 AC 1,517 ms
4,376 KB
testcase_52 AC 1,128 ms
4,380 KB
testcase_53 AC 1,518 ms
4,376 KB
testcase_54 AC 1,505 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = 1e18;
int main(){
  int n, K;
  cin >> n >> K;
  vector<P> A(n);
  rep(i,n) {
    int p, d;
    cin >> p >> d;
    A[i] = make_pair(p, d);
  }
  sort(A.begin(), A.end(), greater<P>());
  vector<vector<ll>> dp(K+1, vector<ll>(2,-INF));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    auto next = dp;
    for (int j = 0; j <= K; j++) {
      if (j + A[i].first <= K) next[j + A[i].first][1] = max(next[j + A[i].first][1], dp[j][0] + A[i].second);
      next[j][0] = max(next[j][0], dp[j][1] + A[i].second);
      next[j][0] = max(next[j][0], dp[j][0]);
      next[j][1] = max(next[j][1], dp[j][1]);
    }
    dp = next;
  }
  ll res = 0;
  for (int i = 0; i <= K; i++) res = max(res, max(dp[i][0], dp[i][1]));
  cout << res << endl;
  return 0;
}
0