結果

問題 No.617 Nafmo、買い出しに行く
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-28 18:21:42
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 71,888 KB
実行使用メモリ 56,516 KB
最終ジャッジ日時 2023-08-23 11:24:20
合計ジャッジ時間 6,663 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,024 KB
testcase_01 AC 123 ms
55,980 KB
testcase_02 AC 122 ms
55,840 KB
testcase_03 AC 138 ms
55,872 KB
testcase_04 AC 122 ms
55,684 KB
testcase_05 AC 139 ms
55,624 KB
testcase_06 AC 220 ms
56,104 KB
testcase_07 AC 222 ms
55,820 KB
testcase_08 WA -
testcase_09 AC 121 ms
56,064 KB
testcase_10 AC 220 ms
55,732 KB
testcase_11 AC 220 ms
56,200 KB
testcase_12 AC 219 ms
56,516 KB
testcase_13 AC 215 ms
56,144 KB
testcase_14 AC 221 ms
56,076 KB
testcase_15 WA -
testcase_16 AC 213 ms
55,788 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 121 ms
56,288 KB
testcase_20 AC 121 ms
55,784 KB
testcase_21 AC 122 ms
55,664 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 = Integer.MIN_VALUE;
		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