結果

問題 No.617 Nafmo、買い出しに行く
ユーザー takeya_okino
提出日時 2018-01-07 20:52:58
言語 Java
(openjdk 23)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 523 bytes
コンパイル時間 2,480 ms
コンパイル使用メモリ 74,088 KB
実行使用メモリ 41,488 KB
最終ジャッジ日時 2024-12-23 10:13:01
合計ジャッジ時間 7,709 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

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