結果

問題 No.617 Nafmo、買い出しに行く
ユーザー takeya_okinotakeya_okino
提出日時 2018-01-07 20:52:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 267 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 71,356 KB
実行使用メモリ 56,304 KB
最終ジャッジ日時 2023-08-24 23:38:46
合計ジャッジ時間 7,409 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,688 KB
testcase_01 AC 122 ms
55,972 KB
testcase_02 AC 126 ms
55,860 KB
testcase_03 AC 147 ms
53,932 KB
testcase_04 AC 124 ms
55,932 KB
testcase_05 AC 145 ms
55,840 KB
testcase_06 AC 263 ms
56,016 KB
testcase_07 AC 264 ms
55,632 KB
testcase_08 AC 121 ms
56,112 KB
testcase_09 AC 122 ms
55,968 KB
testcase_10 AC 264 ms
56,304 KB
testcase_11 AC 264 ms
56,024 KB
testcase_12 AC 267 ms
55,948 KB
testcase_13 AC 261 ms
55,996 KB
testcase_14 AC 265 ms
55,636 KB
testcase_15 AC 235 ms
55,912 KB
testcase_16 AC 258 ms
55,904 KB
testcase_17 AC 234 ms
55,616 KB
testcase_18 AC 121 ms
55,620 KB
testcase_19 AC 121 ms
55,624 KB
testcase_20 AC 121 ms
55,988 KB
testcase_21 AC 123 ms
55,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    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 ans = 0;
    for(int i = 1; i < (int)Math.pow(2, n); i++) {
      int s = 0;
      for(int j = 0; j < n; j++) {
        if((i & (1 << j)) != 0) s += a[j];
      }
      if(s <= k) ans = Math.max(s, ans); 
    }
    System.out.println(ans);
  }
}
0