結果

問題 No.617 Nafmo、買い出しに行く
ユーザー shinwisteria
提出日時 2018-03-07 19:18:11
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 821 bytes
コンパイル時間 3,716 ms
コンパイル使用メモリ 79,228 KB
実行使用メモリ 117,628 KB
最終ジャッジ日時 2024-10-04 02:30:10
合計ジャッジ時間 9,392 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 6 RE * 3
権限があれば一括ダウンロードができます

ソースコード

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