結果
| 問題 | No.617 Nafmo、買い出しに行く | 
| コンテスト | |
| ユーザー |  bal4u | 
| 提出日時 | 2019-05-19 07:23:07 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 74 ms / 2,000 ms | 
| コード長 | 684 bytes | 
| コンパイル時間 | 310 ms | 
| コンパイル使用メモリ | 30,336 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-17 06:26:14 | 
| 合計ジャッジ時間 | 1,332 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 20 | 
ソースコード
// 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;
}
            
            
            
        