結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー 👑 emthrmemthrm
提出日時 2019-12-14 00:08:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,829 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 134,280 KB
実行使用メモリ 814,460 KB
最終ジャッジ日時 2023-09-10 07:09:32
合計ジャッジ時間 5,173 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 53 ms
34,600 KB
testcase_10 AC 31 ms
20,836 KB
testcase_11 AC 32 ms
21,652 KB
testcase_12 AC 477 ms
272,428 KB
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n, k; cin >> n >> k;
  vector<pair<int, int> > pd(n); REP(i, n) cin >> pd[i].first >> pd[i].second;
  sort(pd.rbegin(), pd.rend());
  vector<vector<vector<int> > > dp(n + 1, vector<vector<int> >(k + 1, vector<int>(2, -INF)));
  dp[0][0][false] = 0;
  REP(i, n) REP(j, k + 1) {
    REP(l, 2) dp[i + 1][j][l] = max(dp[i + 1][j][l], dp[i][j][l]);
    if (j + pd[i].first <= k) dp[i + 1][j + pd[i].first][true] = max(dp[i + 1][j + pd[i].first][true], dp[i][j][false] + pd[i].second);
    dp[i + 1][j][false] = max(dp[i + 1][j][false], dp[i][j][true] + pd[i].second);
  }
  int ans = 0;
  REP(j, k + 1) ans = max({ans, dp[n][j][false], dp[n][j][true]});
  cout << ans << '\n';
  return 0;
}
0