結果

問題 No.617 Nafmo、買い出しに行く
ユーザー shinwisteriashinwisteria
提出日時 2018-03-07 19:18:11
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 4,003 ms
コンパイル使用メモリ 79,464 KB
実行使用メモリ 116,456 KB
最終ジャッジ日時 2024-04-14 22:24:14
合計ジャッジ時間 9,934 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 133 ms
54,024 KB
testcase_02 AC 181 ms
63,156 KB
testcase_03 WA -
testcase_04 AC 156 ms
59,116 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 134 ms
54,416 KB
testcase_09 AC 132 ms
54,032 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 227 ms
66,468 KB
testcase_14 AC 246 ms
78,160 KB
testcase_15 AC 134 ms
54,260 KB
testcase_16 AC 136 ms
54,264 KB
testcase_17 RE -
testcase_18 AC 134 ms
54,248 KB
testcase_19 AC 131 ms
53,964 KB
testcase_20 AC 132 ms
53,892 KB
testcase_21 AC 132 ms
54,352 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-1);
						max = Math.max(max, i + add);
					}
				}
			}
		}
		System.out.println(max);
	}

}
0