結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー QCFiumQCFium
提出日時 2020-01-23 20:28:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 169,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 10:36:34
合計ジャッジ時間 6,693 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 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,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 64 ms
4,376 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 13 ms
4,376 KB
testcase_16 AC 26 ms
4,376 KB
testcase_17 AC 60 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 69 ms
4,376 KB
testcase_25 AC 69 ms
4,376 KB
testcase_26 AC 67 ms
4,380 KB
testcase_27 AC 67 ms
4,380 KB
testcase_28 AC 59 ms
4,376 KB
testcase_29 AC 60 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 3 ms
4,376 KB
testcase_35 AC 68 ms
4,380 KB
testcase_36 AC 68 ms
4,380 KB
testcase_37 AC 68 ms
4,376 KB
testcase_38 AC 69 ms
4,376 KB
testcase_39 AC 69 ms
4,380 KB
testcase_40 AC 68 ms
4,376 KB
testcase_41 AC 68 ms
4,376 KB
testcase_42 AC 67 ms
4,380 KB
testcase_43 AC 67 ms
4,376 KB
testcase_44 AC 67 ms
4,376 KB
testcase_45 AC 67 ms
4,380 KB
testcase_46 AC 60 ms
4,380 KB
testcase_47 AC 60 ms
4,380 KB
testcase_48 AC 60 ms
4,376 KB
testcase_49 AC 60 ms
4,380 KB
testcase_50 AC 60 ms
4,380 KB
testcase_51 AC 60 ms
4,376 KB
testcase_52 AC 69 ms
4,380 KB
testcase_53 AC 69 ms
4,376 KB
testcase_54 AC 50 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri(), k = ri();
	std::pair<int, int> a[n];
	for (auto &i : a) i.first = ri(), i.second = ri();
	std::sort(a, a + n, std::greater<>());
	int dp[5001][2]; // {cost, left}
	for (auto &i : dp) i[0] = 0, i[1] = -1000000000;
	for (int i = 0; i < n; i++) {
		for (int j = 5000; j >= 0; j--) {
			int cost = a[i].first;
			if (j <= 5000 - cost) dp[j + cost][1] = std::max(dp[j + cost][1], dp[j][0] + a[i].second);
			dp[j][0] = std::max(dp[j][0], dp[j][1] + a[i].second);
		}
	}
	int res = 0;
	for (int i = 0; i <= k; i++) res = std::max({res, dp[i][0], dp[i][1]});
	printf("%d\n", res);
	return 0;
}
0