結果
問題 |
No.617 Nafmo、買い出しに行く
|
ユーザー |
![]() |
提出日時 | 2018-02-28 18:22:48 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 240 ms / 2,000 ms |
コード長 | 519 bytes |
コンパイル時間 | 2,263 ms |
コンパイル使用メモリ | 74,172 KB |
実行使用メモリ | 41,740 KB |
最終ジャッジ日時 | 2024-12-21 13:55:57 |
合計ジャッジ時間 | 7,147 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
import java.util.*; import static java.lang.System.*; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int n = sc.nextInt(); int limit = sc.nextInt(); int[] ar = new int[n]; int max = 0; int temp; for (int i=0; i<n; i++) { ar[i] = sc.nextInt(); } for (int i=1; i<(1<<n); i++) { temp = 0; for (int j=0; j<n; j++) { if ((1&i>>j)==1) {temp += ar[j];} } if (temp <= limit) {max = Math.max(max,temp);} } out.println(max); } }