結果
| 問題 |
No.617 Nafmo、買い出しに行く
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-05 10:48:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 226 ms / 2,000 ms |
| コード長 | 896 bytes |
| コンパイル時間 | 2,181 ms |
| コンパイル使用メモリ | 77,276 KB |
| 実行使用メモリ | 41,644 KB |
| 最終ジャッジ日時 | 2024-11-28 16:31:13 |
| 合計ジャッジ時間 | 6,961 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
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));
}
}