結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
41,468 KB
testcase_01 AC 128 ms
41,684 KB
testcase_02 AC 218 ms
65,748 KB
testcase_03 AC 216 ms
65,936 KB
testcase_04 AC 228 ms
65,840 KB
testcase_05 AC 220 ms
66,120 KB
testcase_06 AC 234 ms
66,032 KB
testcase_07 AC 223 ms
64,680 KB
testcase_08 AC 233 ms
65,832 KB
testcase_09 AC 229 ms
66,140 KB
testcase_10 AC 214 ms
66,172 KB
testcase_11 AC 220 ms
65,784 KB
testcase_12 AC 227 ms
65,564 KB
testcase_13 AC 230 ms
65,036 KB
testcase_14 AC 234 ms
65,460 KB
testcase_15 AC 216 ms
65,472 KB
testcase_16 AC 229 ms
65,648 KB
testcase_17 AC 228 ms
66,288 KB
testcase_18 AC 225 ms
65,484 KB
testcase_19 AC 230 ms
65,880 KB
testcase_20 AC 227 ms
66,116 KB
testcase_21 AC 232 ms
65,364 KB
testcase_22 AC 343 ms
95,980 KB
testcase_23 AC 142 ms
41,376 KB
testcase_24 AC 314 ms
79,412 KB
testcase_25 AC 109 ms
41,728 KB
testcase_26 AC 113 ms
41,592 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