結果

問題 No.617 Nafmo、買い出しに行く
ユーザー tentententen
提出日時 2020-09-07 14:16:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 592 bytes
コンパイル時間 3,153 ms
コンパイル使用メモリ 70,956 KB
実行使用メモリ 58,400 KB
最終ジャッジ日時 2023-08-19 16:45:14
合計ジャッジ時間 7,823 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,092 KB
testcase_01 AC 107 ms
55,620 KB
testcase_02 AC 120 ms
55,732 KB
testcase_03 AC 129 ms
55,912 KB
testcase_04 AC 122 ms
56,004 KB
testcase_05 AC 136 ms
57,568 KB
testcase_06 AC 151 ms
58,152 KB
testcase_07 AC 150 ms
57,696 KB
testcase_08 AC 106 ms
54,020 KB
testcase_09 AC 105 ms
55,944 KB
testcase_10 AC 142 ms
58,280 KB
testcase_11 AC 148 ms
58,400 KB
testcase_12 AC 135 ms
55,708 KB
testcase_13 AC 133 ms
55,852 KB
testcase_14 AC 129 ms
55,680 KB
testcase_15 AC 107 ms
56,052 KB
testcase_16 AC 105 ms
56,084 KB
testcase_17 AC 111 ms
55,832 KB
testcase_18 AC 105 ms
56,096 KB
testcase_19 AC 107 ms
55,688 KB
testcase_20 AC 105 ms
56,160 KB
testcase_21 AC 114 ms
55,452 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();
    	boolean[] sums = new boolean[k + 1];
    	sums[0] = true;
    	for (int i = 0; i < n; i++) {
    	    int x = sc.nextInt();
    	    for (int j = k - x; j >= 0; j--) {
    	        if (sums[j]) {
    	            sums[j + x] = true;
    	        }
    	    }
    	}
    	for (int i = k; i >= 0; i--) {
    	    if (sums[i]) {
    	        System.out.println(i);
    	        return;
    	    }
    	}
   }
}
0