結果

問題 No.710 チーム戦
ユーザー tentententen
提出日時 2020-09-02 13:49:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 404 ms / 3,000 ms
コード長 1,168 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 77,344 KB
実行使用メモリ 95,544 KB
最終ジャッジ日時 2024-11-21 14:09:04
合計ジャッジ時間 10,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
41,120 KB
testcase_01 AC 130 ms
41,564 KB
testcase_02 AC 262 ms
65,312 KB
testcase_03 AC 263 ms
65,836 KB
testcase_04 AC 272 ms
65,768 KB
testcase_05 AC 258 ms
65,952 KB
testcase_06 AC 279 ms
65,964 KB
testcase_07 AC 263 ms
65,044 KB
testcase_08 AC 287 ms
65,632 KB
testcase_09 AC 271 ms
65,940 KB
testcase_10 AC 257 ms
65,900 KB
testcase_11 AC 262 ms
65,640 KB
testcase_12 AC 278 ms
65,256 KB
testcase_13 AC 278 ms
65,208 KB
testcase_14 AC 271 ms
65,568 KB
testcase_15 AC 255 ms
65,428 KB
testcase_16 AC 278 ms
65,132 KB
testcase_17 AC 254 ms
66,228 KB
testcase_18 AC 260 ms
65,396 KB
testcase_19 AC 279 ms
65,784 KB
testcase_20 AC 261 ms
65,948 KB
testcase_21 AC 274 ms
65,232 KB
testcase_22 AC 404 ms
95,544 KB
testcase_23 AC 145 ms
41,800 KB
testcase_24 AC 367 ms
79,104 KB
testcase_25 AC 123 ms
41,200 KB
testcase_26 AC 120 ms
41,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] arrA;
    static int[] arrB;
    static int[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        arrA = new int[n];
        arrB = new int[n];
        int sumA = 0;
        int sumB = 0;
        for (int i = 0; i < n; i++) {
            arrA[i] = sc.nextInt();
            sumA += arrA[i];
            arrB[i] = sc.nextInt();
            sumB += arrB[i];
        }
        dp = new int[n][sumA + 1];
        for (int[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i <= sumA; i++) {
            min = Math.min(min, Math.max(i, sumB - dfw(n - 1, i)));
        }
        System.out.println(min);
    }
    
    static int dfw(int idx, int time) {
        if (time < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][time] == -1) {
            dp[idx][time] = Math.max(dfw(idx - 1, time), dfw(idx - 1, time - arrA[idx]) + arrB[idx]);
        }
        return dp[idx][time];
    }
}
0