結果

問題 No.617 Nafmo、買い出しに行く
ユーザー 37zigen37zigen
提出日時 2017-12-05 10:48:42
言語 Java19
(openjdk 21)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 2,747 ms
コンパイル使用メモリ 79,052 KB
実行使用メモリ 56,032 KB
最終ジャッジ日時 2023-08-19 03:19:37
合計ジャッジ時間 7,571 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,708 KB
testcase_01 AC 124 ms
55,688 KB
testcase_02 AC 122 ms
55,408 KB
testcase_03 AC 140 ms
56,032 KB
testcase_04 AC 124 ms
55,620 KB
testcase_05 AC 147 ms
55,676 KB
testcase_06 AC 226 ms
55,828 KB
testcase_07 AC 221 ms
54,308 KB
testcase_08 AC 122 ms
55,924 KB
testcase_09 AC 123 ms
55,744 KB
testcase_10 AC 221 ms
55,856 KB
testcase_11 AC 229 ms
55,664 KB
testcase_12 AC 247 ms
55,708 KB
testcase_13 AC 249 ms
55,968 KB
testcase_14 AC 254 ms
55,616 KB
testcase_15 AC 225 ms
55,660 KB
testcase_16 AC 250 ms
55,444 KB
testcase_17 AC 231 ms
55,704 KB
testcase_18 AC 125 ms
55,856 KB
testcase_19 AC 120 ms
55,888 KB
testcase_20 AC 122 ms
55,632 KB
testcase_21 AC 118 ms
56,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package tester;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if (!(1 <= N && N <= 20))
			throw new AssertionError();
		if (!(0 <= K && K <= 2000000))
			throw new AssertionError();
		int[] A = new int[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextInt();
			if (!(1 <= A[i] && A[i] <= 100000))
				throw new AssertionError();

		}
		int ans = 0;
		for (int s = 0; s < 1 << N; ++s) {
			int tmp = 0;
			for (int i = 0; i < N; ++i) {
				if ((s >> i) % 2 == 1) {
					tmp += A[i];
				}
			}
			if (tmp <= K) {
				ans = Math.max(ans, tmp);
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0