結果

問題 No.617 Nafmo、買い出しに行く
ユーザー GrenacheGrenache
提出日時 2017-12-17 00:16:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 3,241 ms
コンパイル使用メモリ 72,308 KB
実行使用メモリ 56,352 KB
最終ジャッジ日時 2023-08-21 11:42:18
合計ジャッジ時間 8,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,060 KB
testcase_01 AC 120 ms
55,984 KB
testcase_02 AC 122 ms
55,760 KB
testcase_03 AC 145 ms
55,540 KB
testcase_04 AC 124 ms
56,236 KB
testcase_05 AC 144 ms
55,880 KB
testcase_06 AC 239 ms
55,492 KB
testcase_07 AC 235 ms
55,764 KB
testcase_08 AC 121 ms
55,692 KB
testcase_09 AC 120 ms
55,492 KB
testcase_10 AC 233 ms
56,352 KB
testcase_11 AC 239 ms
56,136 KB
testcase_12 AC 218 ms
55,888 KB
testcase_13 AC 215 ms
55,832 KB
testcase_14 AC 219 ms
55,680 KB
testcase_15 AC 217 ms
55,848 KB
testcase_16 AC 216 ms
56,204 KB
testcase_17 AC 217 ms
55,392 KB
testcase_18 AC 121 ms
55,692 KB
testcase_19 AC 119 ms
55,976 KB
testcase_20 AC 120 ms
55,836 KB
testcase_21 AC 121 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder617 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int max = 0;
		for (int i = 0; i < 0x1 << n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				if ((i & 0x1 << j) != 0) {
					sum += a[j];
				}
			}

			if (sum <= k) {
				max = Math.max(max, sum);
			}
		}

		pr.println(max);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0