結果
問題 | No.617 Nafmo、買い出しに行く |
ユーザー |
|
提出日時 | 2017-12-17 00:16:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 853 bytes |
コンパイル時間 | 3,820 ms |
コンパイル使用メモリ | 75,176 KB |
実行使用メモリ | 54,436 KB |
最終ジャッジ日時 | 2024-12-14 22:33:40 |
合計ジャッジ時間 | 8,808 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
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);}}}