結果
| 問題 |
No.904 サメトロ
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2021-08-03 10:37:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 932 bytes |
| コンパイル時間 | 222 ms |
| コンパイル使用メモリ | 82,408 KB |
| 実行使用メモリ | 62,208 KB |
| 最終ジャッジ日時 | 2024-09-16 14:55:14 |
| 合計ジャッジ時間 | 2,875 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 WA * 1 |
ソースコード
import copy
N = int(input())
A = []
B = []
AB = []
for i in range(N-1):
a,b = map(int,input().split())
A.append(a)
B.append(b)
AB.append([a,b])
ma = max(sum(A),sum(B))
AB = sorted(AB, key=lambda x:(x[1]), reverse=True)
A = []
B = []
for i in range(N-1):
A.append(AB[i][0])
B.append(AB[i][1])
amarib = 0
D = copy.deepcopy(A)
for i in range(len(A)):
b = B[i]
for j in reversed(range(len(A))):
if i==j:
continue
temp = min(D[j],b)
b-=temp
D[j]-=temp
amarib += b
AB = sorted(AB, key=lambda x:(x[0]), reverse=True)
A = []
B = []
for i in range(N-1):
A.append(AB[i][0])
B.append(AB[i][1])
amaria = 0
D = copy.deepcopy(B)
for i in range(len(A)):
a = A[i]
for j in reversed(range(len(A))):
if i==j:
continue
temp = min(D[j],a)
a-=temp
D[j]-=temp
amaria += a
print(ma-max(amaria,amarib)+1)
H20