結果

問題 No.393 2本の竹
ユーザー ぴろずぴろず
提出日時 2016-07-12 21:17:12
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 398 ms / 1,000 ms
コード長 984 bytes
コンパイル時間 1,861 ms
使用メモリ 42,292 KB
最終ジャッジ日時 2022-12-14 14:26:33
合計ジャッジ時間 9,052 ms
ジャッジサーバーID
(参考情報)
judge14 / judge16
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 162 ms
40,240 KB
testcase_01 AC 132 ms
39,028 KB
testcase_02 AC 148 ms
38,724 KB
testcase_03 AC 174 ms
40,176 KB
testcase_04 AC 138 ms
38,616 KB
testcase_05 AC 131 ms
38,988 KB
testcase_06 AC 121 ms
38,364 KB
testcase_07 AC 149 ms
41,864 KB
testcase_08 AC 200 ms
40,544 KB
testcase_09 AC 398 ms
42,208 KB
testcase_10 AC 255 ms
41,808 KB
testcase_11 AC 259 ms
42,020 KB
testcase_12 AC 279 ms
40,472 KB
testcase_13 AC 245 ms
41,964 KB
testcase_14 AC 233 ms
42,292 KB
testcase_15 AC 176 ms
39,620 KB
testcase_16 AC 214 ms
41,068 KB
testcase_17 AC 136 ms
38,632 KB
testcase_18 AC 130 ms
39,320 KB
testcase_19 AC 129 ms
38,364 KB
testcase_20 AC 125 ms
39,740 KB
testcase_21 AC 186 ms
39,904 KB
testcase_22 AC 257 ms
41,256 KB
testcase_23 AC 249 ms
42,292 KB
testcase_24 AC 189 ms
40,468 KB
testcase_25 AC 166 ms
40,336 KB
testcase_26 AC 137 ms
39,220 KB
testcase_27 AC 385 ms
41,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no393;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int d = sc.nextInt();
		for(int i=0;i<d;i++) {
			solve();
		}
	}
	
	public static int LMAX = 100000;
	static boolean[] dp = new boolean[LMAX+1];
	public static void solve() {
		int l1 = sc.nextInt();
		int l2 = sc.nextInt();
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int l = 0;
		int r = n + 1;
		while(l + 1 < r) {
			int c = (l + r) / 2;
			Arrays.fill(dp, false);
			dp[0] = true;
			int sum = 0;
			for(int i=0;i<c;i++) {
				sum += a[i];
				for(int j=l1;j>=a[i];j--) {
					dp[j] |= dp[j-a[i]];
				}
			}
			boolean flag = false;
			for(int i=l1;i>=0;i--) {
				if (dp[i]) {
					flag = sum - i <= l2;
					break;
				}
			}
			if (flag) {
				l = c;
			}else{
				r = c;
			}
		}
		System.out.println(l);
	}

}
0