結果

問題 No.393 2本の竹
ユーザー ぴろずぴろず
提出日時 2016-07-12 21:17:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 435 ms / 1,000 ms
コード長 984 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 77,912 KB
実行使用メモリ 55,536 KB
最終ジャッジ日時 2024-04-25 18:16:45
合計ジャッジ時間 8,640 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 171 ms
54,512 KB
testcase_01 AC 134 ms
53,872 KB
testcase_02 AC 155 ms
53,820 KB
testcase_03 AC 170 ms
54,384 KB
testcase_04 AC 157 ms
54,328 KB
testcase_05 AC 159 ms
54,516 KB
testcase_06 AC 150 ms
54,212 KB
testcase_07 AC 172 ms
54,432 KB
testcase_08 AC 180 ms
54,412 KB
testcase_09 AC 434 ms
55,444 KB
testcase_10 AC 252 ms
55,228 KB
testcase_11 AC 290 ms
54,852 KB
testcase_12 AC 288 ms
55,132 KB
testcase_13 AC 263 ms
55,428 KB
testcase_14 AC 241 ms
55,260 KB
testcase_15 AC 170 ms
53,660 KB
testcase_16 AC 230 ms
54,780 KB
testcase_17 AC 171 ms
54,500 KB
testcase_18 AC 164 ms
54,236 KB
testcase_19 AC 128 ms
53,436 KB
testcase_20 AC 149 ms
54,192 KB
testcase_21 AC 160 ms
54,032 KB
testcase_22 AC 297 ms
55,132 KB
testcase_23 AC 244 ms
55,536 KB
testcase_24 AC 170 ms
54,556 KB
testcase_25 AC 169 ms
54,156 KB
testcase_26 AC 145 ms
54,304 KB
testcase_27 AC 435 ms
55,492 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