結果

問題 No.617 Nafmo、買い出しに行く
ユーザー bal4ubal4u
提出日時 2019-05-19 07:23:07
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 30,192 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 07:52:08
合計ジャッジ時間 1,342 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 5 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 68 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 68 ms
4,348 KB
testcase_13 AC 69 ms
4,348 KB
testcase_14 AC 69 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: 617 Nafmo、買い出しに行く
// 2019.5.12 bal4u

#include <stdio.h>

#if 0
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

int A[22], sz;

int main()
{
	int i, j, N, K, s, lim, ans;
	
	N = in(), K = in();
	s = 0; while (N--) {
		A[sz] = in();
		if (A[sz] <= K) { s += A[sz]; sz++; }
	}
	if (s <= K) ans = s;
	else {
		lim = 1 << sz, ans = 0;
		for (i = 1; i < lim; i++) {
			s = 0;
			for (j = 0; j < sz; j++) if ((i >> j) & 1) s += A[j];
			if (s <= K && s > ans) ans = s;
		}
	}
	printf("%d\n", ans);
	return 0;
}
0