結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-13 12:06:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 206,360 KB
実行使用メモリ 199,768 KB
最終ジャッジ日時 2023-09-07 05:45:56
合計ジャッジ時間 12,589 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
199,596 KB
testcase_01 AC 82 ms
199,452 KB
testcase_02 AC 84 ms
199,428 KB
testcase_03 AC 80 ms
199,700 KB
testcase_04 AC 84 ms
199,516 KB
testcase_05 AC 80 ms
199,512 KB
testcase_06 AC 96 ms
199,472 KB
testcase_07 AC 66 ms
199,456 KB
testcase_08 AC 66 ms
199,476 KB
testcase_09 AC 70 ms
199,488 KB
testcase_10 AC 68 ms
199,456 KB
testcase_11 AC 69 ms
199,436 KB
testcase_12 AC 93 ms
199,540 KB
testcase_13 AC 158 ms
199,600 KB
testcase_14 AC 80 ms
199,768 KB
testcase_15 AC 78 ms
199,488 KB
testcase_16 AC 86 ms
199,484 KB
testcase_17 AC 94 ms
199,524 KB
testcase_18 AC 61 ms
199,452 KB
testcase_19 AC 61 ms
199,472 KB
testcase_20 AC 60 ms
199,484 KB
testcase_21 AC 63 ms
199,476 KB
testcase_22 AC 64 ms
199,544 KB
testcase_23 AC 60 ms
199,524 KB
testcase_24 AC 185 ms
199,600 KB
testcase_25 AC 194 ms
199,624 KB
testcase_26 AC 197 ms
199,532 KB
testcase_27 AC 192 ms
199,592 KB
testcase_28 AC 166 ms
199,496 KB
testcase_29 AC 167 ms
199,660 KB
testcase_30 AC 58 ms
199,452 KB
testcase_31 AC 58 ms
199,420 KB
testcase_32 AC 61 ms
199,488 KB
testcase_33 AC 62 ms
199,420 KB
testcase_34 AC 61 ms
199,584 KB
testcase_35 AC 168 ms
199,600 KB
testcase_36 AC 178 ms
199,548 KB
testcase_37 AC 173 ms
199,564 KB
testcase_38 AC 190 ms
199,504 KB
testcase_39 AC 193 ms
199,728 KB
testcase_40 AC 173 ms
199,552 KB
testcase_41 AC 186 ms
199,668 KB
testcase_42 AC 188 ms
199,540 KB
testcase_43 AC 189 ms
199,512 KB
testcase_44 AC 191 ms
199,508 KB
testcase_45 AC 190 ms
199,500 KB
testcase_46 AC 168 ms
199,544 KB
testcase_47 AC 171 ms
199,536 KB
testcase_48 AC 172 ms
199,756 KB
testcase_49 AC 171 ms
199,752 KB
testcase_50 AC 170 ms
199,504 KB
testcase_51 AC 171 ms
199,624 KB
testcase_52 AC 157 ms
199,560 KB
testcase_53 AC 179 ms
199,596 KB
testcase_54 AC 159 ms
199,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int dp[5010][5010][2];

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<pll> p(N);
  rep(i, N) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end(), greater<pll>());
  rep(i, 5010) rep(j, 5010) rep(k, 2) dp[i][j][k] = -INF;
  rep(j, 5010) dp[0][j][0] = 0;
  rep(i, N) rep(j, K+1) {
    rep(k, 2) {
      if(dp[i][j][k] == -INF) continue;
      chmax(dp[i+1][j][k], dp[i][j][k]);
    }
    if(dp[i][j][0] != -INF && j+p[i].first <= K) chmax(dp[i+1][j+p[i].first][1], dp[i][j][0]+p[i].second);
    if(dp[i][j][0] != -INF) chmax(dp[i+1][j][0], dp[i][j][1]+p[i].second);
  }
  int ans = -INF;
  rep(j, 5010) rep(k, 2) chmax(ans, dp[N][j][k]);
  cout << ans << '\n';
  return 0;
}
0