結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2019-12-19 11:02:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 1,692 ms
コンパイル使用メモリ 170,592 KB
実行使用メモリ 199,732 KB
最終ジャッジ日時 2023-09-21 06:37:06
合計ジャッジ時間 8,794 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
199,416 KB
testcase_01 AC 103 ms
199,560 KB
testcase_02 AC 67 ms
199,412 KB
testcase_03 AC 67 ms
199,416 KB
testcase_04 AC 65 ms
199,496 KB
testcase_05 AC 66 ms
199,380 KB
testcase_06 AC 65 ms
199,420 KB
testcase_07 AC 65 ms
199,488 KB
testcase_08 AC 65 ms
199,388 KB
testcase_09 AC 66 ms
199,448 KB
testcase_10 AC 65 ms
199,380 KB
testcase_11 AC 66 ms
199,432 KB
testcase_12 AC 76 ms
199,388 KB
testcase_13 AC 103 ms
199,464 KB
testcase_14 AC 72 ms
199,436 KB
testcase_15 AC 71 ms
199,396 KB
testcase_16 AC 73 ms
199,576 KB
testcase_17 AC 78 ms
199,664 KB
testcase_18 AC 65 ms
199,432 KB
testcase_19 AC 66 ms
199,624 KB
testcase_20 AC 65 ms
199,568 KB
testcase_21 AC 66 ms
199,448 KB
testcase_22 AC 65 ms
199,392 KB
testcase_23 AC 65 ms
199,384 KB
testcase_24 AC 117 ms
199,460 KB
testcase_25 AC 116 ms
199,472 KB
testcase_26 AC 117 ms
199,468 KB
testcase_27 AC 117 ms
199,424 KB
testcase_28 AC 112 ms
199,524 KB
testcase_29 AC 111 ms
199,424 KB
testcase_30 AC 66 ms
199,416 KB
testcase_31 AC 66 ms
199,476 KB
testcase_32 AC 65 ms
199,380 KB
testcase_33 AC 67 ms
199,424 KB
testcase_34 AC 66 ms
199,484 KB
testcase_35 AC 116 ms
199,428 KB
testcase_36 AC 117 ms
199,664 KB
testcase_37 AC 118 ms
199,732 KB
testcase_38 AC 116 ms
199,416 KB
testcase_39 AC 118 ms
199,524 KB
testcase_40 AC 116 ms
199,468 KB
testcase_41 AC 116 ms
199,540 KB
testcase_42 AC 117 ms
199,732 KB
testcase_43 AC 121 ms
199,516 KB
testcase_44 AC 115 ms
199,464 KB
testcase_45 AC 114 ms
199,412 KB
testcase_46 AC 110 ms
199,664 KB
testcase_47 AC 111 ms
199,416 KB
testcase_48 AC 111 ms
199,668 KB
testcase_49 AC 112 ms
199,460 KB
testcase_50 AC 110 ms
199,416 KB
testcase_51 AC 109 ms
199,660 KB
testcase_52 AC 109 ms
199,428 KB
testcase_53 AC 116 ms
199,536 KB
testcase_54 AC 104 ms
199,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAX = 5010;
int dp[MAX][MAX][2];
int main() {
	int N, K; cin >> N >> K;
	pair<int, int> p[N];
	for(int i = 0; i < N; ++i) {
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p + N);
	reverse(p, p + N);
	for(int i = 0; i < MAX; ++i) {
		for(int j = 0; j < MAX; ++j) {
			for(int k = 0; k < 2; ++k) {
				dp[i][j][k] = -1e9;
			}
		}
	}
	dp[0][0][0] = 0;
	for(int i = 1; i <= N; ++i) {
		int cos, val;
		tie(cos, val) = p[i - 1];
		for(int j = 0; j <= K; ++j) {
			dp[i][j][0] = dp[i - 1][j][0];
			dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][1] + val);
			dp[i][j][1] = dp[i - 1][j][1];
			if(j - cos >= 0) {
				dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j - cos][0] + val);
			}
		}
	}
	int ans = 0;
	for(int j = 0; j <= K; ++j) {
		for(int k = 0; k < 2; ++k) {
			ans = max(ans, dp[N][j][k]);
		}
	}
	cout << ans << '\n';
	return 0;
}
0