結果

問題 No.393 2本の竹
ユーザー ぴろずぴろず
提出日時 2016-07-12 21:17:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 377 ms / 1,000 ms
コード長 984 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 73,856 KB
実行使用メモリ 58,164 KB
最終ジャッジ日時 2023-08-08 00:11:31
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 191 ms
56,476 KB
testcase_01 AC 154 ms
55,676 KB
testcase_02 AC 165 ms
56,000 KB
testcase_03 AC 186 ms
56,140 KB
testcase_04 AC 155 ms
55,980 KB
testcase_05 AC 184 ms
56,400 KB
testcase_06 AC 153 ms
55,944 KB
testcase_07 AC 193 ms
56,964 KB
testcase_08 AC 201 ms
57,096 KB
testcase_09 AC 377 ms
57,256 KB
testcase_10 AC 278 ms
57,144 KB
testcase_11 AC 299 ms
57,164 KB
testcase_12 AC 291 ms
57,176 KB
testcase_13 AC 291 ms
57,440 KB
testcase_14 AC 284 ms
57,556 KB
testcase_15 AC 191 ms
56,092 KB
testcase_16 AC 237 ms
57,052 KB
testcase_17 AC 183 ms
55,968 KB
testcase_18 AC 182 ms
55,856 KB
testcase_19 AC 146 ms
55,888 KB
testcase_20 AC 152 ms
56,208 KB
testcase_21 AC 180 ms
56,460 KB
testcase_22 AC 268 ms
57,464 KB
testcase_23 AC 248 ms
58,164 KB
testcase_24 AC 191 ms
56,364 KB
testcase_25 AC 177 ms
55,948 KB
testcase_26 AC 144 ms
53,628 KB
testcase_27 AC 375 ms
57,528 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