結果

問題 No.617 Nafmo、買い出しに行く
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-28 18:22:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 1,856 ms
コンパイル使用メモリ 72,088 KB
実行使用メモリ 56,208 KB
最終ジャッジ日時 2023-08-23 11:24:36
合計ジャッジ時間 6,499 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,924 KB
testcase_01 AC 121 ms
55,920 KB
testcase_02 AC 124 ms
53,808 KB
testcase_03 AC 138 ms
55,684 KB
testcase_04 AC 122 ms
55,876 KB
testcase_05 AC 137 ms
55,912 KB
testcase_06 AC 220 ms
56,060 KB
testcase_07 AC 219 ms
56,136 KB
testcase_08 AC 121 ms
55,584 KB
testcase_09 AC 120 ms
55,892 KB
testcase_10 AC 219 ms
55,924 KB
testcase_11 AC 220 ms
55,636 KB
testcase_12 AC 217 ms
54,300 KB
testcase_13 AC 211 ms
55,972 KB
testcase_14 AC 217 ms
56,208 KB
testcase_15 AC 200 ms
55,900 KB
testcase_16 AC 211 ms
55,904 KB
testcase_17 AC 198 ms
56,036 KB
testcase_18 AC 121 ms
56,192 KB
testcase_19 AC 122 ms
56,012 KB
testcase_20 AC 120 ms
55,740 KB
testcase_21 AC 123 ms
55,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0