結果
問題 |
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 sys def main(): n = int(sys.stdin.readline()) tasks = [] totalA = 0 totalB = 0 for _ in range(n): a, b = map(int, sys.stdin.readline().split()) tasks.append((a, b)) totalA += a totalB += b low = 0 high = max(totalA, totalB) answer = high def 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 tasks for 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 task if new_dp[a_prev] < dp[a_prev]: new_dp[a_prev] = dp[a_prev] # Option 2: Take the current task with Yukio a_new = a_prev + a_i if a_new > T: continue b_new = dp[a_prev] + b_i if new_dp[a_new] < b_new: new_dp[a_new] = b_new dp = new_dp required_b = totalB - T for a in range(T + 1): if dp[a] >= required_b and a <= T: return True return False while low <= high: mid = (low + high) // 2 if can_achieve(mid): answer = mid high = mid - 1 else: low = mid + 1 print(answer) if __name__ == "__main__": main()