結果

問題 No.617 Nafmo、買い出しに行く
ユーザー sggkshiosggkshio
提出日時 2018-07-09 08:23:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 81,376 KB
実行使用メモリ 42,488 KB
最終ジャッジ日時 2023-09-22 08:28:56
合計ジャッジ時間 1,754 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
17,708 KB
testcase_01 AC 3 ms
7,444 KB
testcase_02 AC 9 ms
23,800 KB
testcase_03 AC 19 ms
34,064 KB
testcase_04 AC 4 ms
13,760 KB
testcase_05 AC 28 ms
36,184 KB
testcase_06 AC 42 ms
42,216 KB
testcase_07 AC 44 ms
42,308 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
5,456 KB
testcase_10 AC 38 ms
42,252 KB
testcase_11 AC 44 ms
42,332 KB
testcase_12 AC 30 ms
42,208 KB
testcase_13 AC 22 ms
42,288 KB
testcase_14 AC 27 ms
42,300 KB
testcase_15 AC 9 ms
42,488 KB
testcase_16 AC 7 ms
42,328 KB
testcase_17 AC 8 ms
42,460 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
5,628 KB
testcase_21 AC 3 ms
9,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>

bool f[22][2000005] = {};
int main() {
	long long int n, k, a[25] = {};
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	int ans = 0;
	f[0][0] = 1;
	
		
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= k; j++) {
				if (!f[i][j])continue;
				f[i + 1][j] = 1;
				if (j + a[i] <= k) {
					f[i + 1][j + a[i]] = 1;
				}
			}
		}
	
	for (int i = k; i >= 0; i--) {
		if (f[n][i]) {
			cout << i<< endl;
			return 0;
		}
	}

	return 0;
}
0