結果

問題 No.617 Nafmo、買い出しに行く
ユーザー GBGB
提出日時 2018-11-09 02:42:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 556 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 64,876 KB
実行使用メモリ 393,940 KB
最終ジャッジ日時 2024-05-01 04:01:32
合計ジャッジ時間 2,828 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
37,848 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 34 ms
48,324 KB
testcase_03 AC 72 ms
114,768 KB
testcase_04 AC 10 ms
13,824 KB
testcase_05 AC 113 ms
197,032 KB
testcase_06 AC 219 ms
393,940 KB
testcase_07 AC 211 ms
393,908 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 155 ms
281,880 KB
testcase_11 AC 183 ms
340,224 KB
testcase_12 AC 109 ms
183,208 KB
testcase_13 AC 74 ms
110,624 KB
testcase_14 AC 91 ms
145,224 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int main() {

	int n = 0,k=0;
	cin >> n>>k;
	vector<ll> weight(n+5,0);
	for (int i = 0;i < n;i++) cin>>weight[i];

	vector<ll> *dp = new vector<ll>[n+5];
	for (int i = 0;i < n + 5;i++)dp[i].resize(k + 5,0);
	for (int i = 0; i < n; ++i) {
		for (int w = 0; w <= k; ++w) {
			if (w >= weight[i]) dp[i + 1][w] = max(dp[i][w - weight[i]] + weight[i], dp[i][w]);
			else dp[i + 1][w] = dp[i][w];
		}
	}

	cout << dp[n][k] << endl;

	delete[] dp;

	return 0;
}
0