結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー ianCKianCK
提出日時 2019-12-14 10:48:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 1,013 ms
コンパイル使用メモリ 42,528 KB
実行使用メモリ 100,992 KB
最終ジャッジ日時 2023-09-10 11:45:50
合計ジャッジ時間 5,262 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 5 ms
10,244 KB
testcase_10 AC 4 ms
6,152 KB
testcase_11 AC 4 ms
9,908 KB
testcase_12 AC 20 ms
25,532 KB
testcase_13 AC 67 ms
92,332 KB
testcase_14 AC 13 ms
17,324 KB
testcase_15 AC 13 ms
23,128 KB
testcase_16 AC 20 ms
41,224 KB
testcase_17 AC 33 ms
75,424 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 3 ms
4,608 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 88 ms
100,880 KB
testcase_25 AC 88 ms
100,924 KB
testcase_26 AC 86 ms
100,968 KB
testcase_27 AC 86 ms
100,888 KB
testcase_28 AC 75 ms
100,920 KB
testcase_29 AC 76 ms
100,956 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 3 ms
4,380 KB
testcase_34 AC 4 ms
4,980 KB
testcase_35 AC 89 ms
100,912 KB
testcase_36 AC 88 ms
100,936 KB
testcase_37 AC 88 ms
100,900 KB
testcase_38 AC 88 ms
100,936 KB
testcase_39 AC 88 ms
100,920 KB
testcase_40 AC 87 ms
100,960 KB
testcase_41 AC 87 ms
100,968 KB
testcase_42 AC 86 ms
100,940 KB
testcase_43 AC 86 ms
100,964 KB
testcase_44 AC 86 ms
100,900 KB
testcase_45 AC 86 ms
100,936 KB
testcase_46 AC 76 ms
100,912 KB
testcase_47 AC 76 ms
100,900 KB
testcase_48 AC 77 ms
100,940 KB
testcase_49 AC 76 ms
100,936 KB
testcase_50 AC 76 ms
100,924 KB
testcase_51 AC 77 ms
100,920 KB
testcase_52 AC 79 ms
100,912 KB
testcase_53 AC 90 ms
100,964 KB
testcase_54 AC 63 ms
100,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
using namespace std;


constexpr int kN = int(5E3 + 10);

struct Product {
	int p, d;
	void in() {
		scanf("%d%d", &p, &d);
		return ;
	}
};

bool cmp(Product a, Product b) {return a.p < b.p;}

Product a[kN];
int dp[kN][kN], x[kN];

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) a[i].in();
	sort(a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < a[i].p; j++) dp[i][j] = dp[i - 1][j];
		for (int j = a[i].p; j <= k; j++) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i].p] + a[i].d);
		for (int j = a[i].p; j <= k; j++) dp[i][j] = max(dp[i][j], x[j - a[i].p] + a[i].d);
		for (int j = 0; j <= k; j++) x[j] = max(x[j], dp[i - 1][j] + a[i].d);
	}
	printf("%d\n", dp[n][k]);
}
0