結果
問題 |
No.617 Nafmo、買い出しに行く
|
ユーザー |
|
提出日時 | 2017-12-05 00:17:18 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,015 bytes |
コンパイル時間 | 4,740 ms |
コンパイル使用メモリ | 79,056 KB |
実行使用メモリ | 41,436 KB |
最終ジャッジ日時 | 2024-11-28 06:35:31 |
合計ジャッジ時間 | 8,785 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 RE * 3 |
ソースコード
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]; HashSet<Integer> set = new HashSet<>(); for (int i = 0; i < N; ++i) { A[i] = sc.nextInt(); if (set.contains(A[i])) throw new AssertionError(); set.add(A[i]); 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)); } }