結果
問題 | No.710 チーム戦 |
ユーザー |
![]() |
提出日時 | 2020-09-02 13:49:24 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
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];}}