結果

問題 No.617 Nafmo、買い出しに行く
ユーザー shinwisteriashinwisteria
提出日時 2018-03-07 19:32:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 3,969 ms
コンパイル使用メモリ 77,616 KB
実行使用メモリ 113,420 KB
最終ジャッジ日時 2024-04-14 22:48:36
合計ジャッジ時間 10,050 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
63,484 KB
testcase_01 AC 137 ms
53,952 KB
testcase_02 AC 190 ms
63,468 KB
testcase_03 AC 247 ms
78,264 KB
testcase_04 AC 157 ms
59,032 KB
testcase_05 AC 321 ms
88,416 KB
testcase_06 AC 386 ms
113,404 KB
testcase_07 AC 383 ms
113,420 KB
testcase_08 AC 137 ms
54,064 KB
testcase_09 AC 135 ms
54,164 KB
testcase_10 AC 343 ms
91,968 KB
testcase_11 AC 374 ms
109,244 KB
testcase_12 AC 263 ms
80,244 KB
testcase_13 AC 227 ms
66,672 KB
testcase_14 AC 254 ms
78,224 KB
testcase_15 AC 137 ms
54,608 KB
testcase_16 AC 139 ms
54,444 KB
testcase_17 AC 137 ms
54,380 KB
testcase_18 AC 133 ms
53,992 KB
testcase_19 AC 134 ms
53,964 KB
testcase_20 AC 136 ms
54,304 KB
testcase_21 AC 136 ms
54,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

		Arrays.sort(A);
		//System.out.println(a[0] + "  " + a[1]);
		int max = 0;
		int[][] d = new int[K+1][2];
		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;
						if(d[i + add][1] != 0){
							d[i + add][1] = Math.min(Math.min(j+1, d[i+add][1]), N);
						}else{
							d[i + add][1] = Math.min(j + 1, N);
						}
						max = Math.max(max, i + add);
					}
				}
			}
		}
		System.out.println(max);
	}

}
0