結果

問題 No.617 Nafmo、買い出しに行く
ユーザー shinwisteriashinwisteria
提出日時 2018-03-06 23:07:55
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 819 bytes
コンパイル時間 5,572 ms
コンパイル使用メモリ 79,848 KB
実行使用メモリ 119,424 KB
最終ジャッジ日時 2023-10-22 00:01:13
合計ジャッジ時間 10,618 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
66,388 KB
testcase_01 AC 138 ms
57,456 KB
testcase_02 AC 184 ms
66,248 KB
testcase_03 AC 244 ms
80,860 KB
testcase_04 AC 158 ms
61,784 KB
testcase_05 AC 312 ms
91,288 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 133 ms
57,272 KB
testcase_09 AC 133 ms
57,372 KB
testcase_10 AC 341 ms
95,052 KB
testcase_11 AC 376 ms
112,956 KB
testcase_12 AC 258 ms
83,288 KB
testcase_13 AC 223 ms
69,604 KB
testcase_14 AC 247 ms
81,304 KB
testcase_15 AC 136 ms
57,276 KB
testcase_16 AC 138 ms
57,552 KB
testcase_17 RE -
testcase_18 AC 133 ms
57,304 KB
testcase_19 AC 132 ms
57,436 KB
testcase_20 AC 135 ms
57,324 KB
testcase_21 AC 133 ms
57,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package m.shin;
import java.util.Scanner;
import java.util.TreeSet;
public class Con617 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt() , K = s.nextInt();
		TreeSet<Integer> A = new TreeSet<>();
		for(int i = 0;i < N;i++){
			A.add(s.nextInt());
		}
		s.close();

		Integer[] a = new Integer[A.size()];
		A.toArray(a);
		//System.out.println(a[0] + "  " + a[1]);
		int max = 0;
		int[][] d = new int[K+1][2];               //[合計値][次に足すaの番号]
		d[0][0] = 1;
		for(int i = 0;i <= K;i++){
			if(d[i][0] == 1){
				for(int j = d[i][1];j < N;j++){
					int add = a[j];
					if(i + add <= K){
						d[i + add][0] = 1;
						d[i + add][1] = Math.min(j+1, N);
						max = Math.max(max, i + add);
					}
				}
			}
		}
		System.out.println(max);
	}

}
0