結果
問題 | No.710 チーム戦 |
ユーザー |
![]() |
提出日時 | 2025-03-20 18:44:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 866 ms / 3,000 ms |
コード長 | 1,588 bytes |
コンパイル時間 | 168 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 247,360 KB |
最終ジャッジ日時 | 2025-03-20 18:44:41 |
合計ジャッジ時間 | 11,610 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
import sysdef main():n = int(sys.stdin.readline())tasks = []totalA = 0totalB = 0for _ in range(n):a, b = map(int, sys.stdin.readline().split())tasks.append((a, b))totalA += atotalB += blow = 0high = max(totalA, totalB)answer = highdef can_achieve(T):# DP[a] represents the maximum sum of B_i for the chosen tasks where Yukio's total time is exactly 'a'dp = [-1] * (T + 1)dp[0] = 0 # Initial state: choosing no tasksfor a_i, b_i in tasks:new_dp = [-1] * (T + 1)for a_prev in range(T + 1):if dp[a_prev] == -1:continue# Option 1: Do not take the current taskif new_dp[a_prev] < dp[a_prev]:new_dp[a_prev] = dp[a_prev]# Option 2: Take the current task with Yukioa_new = a_prev + a_iif a_new > T:continueb_new = dp[a_prev] + b_iif new_dp[a_new] < b_new:new_dp[a_new] = b_newdp = new_dprequired_b = totalB - Tfor a in range(T + 1):if dp[a] >= required_b and a <= T:return Truereturn Falsewhile low <= high:mid = (low + high) // 2if can_achieve(mid):answer = midhigh = mid - 1else:low = mid + 1print(answer)if __name__ == "__main__":main()