結果

問題 No.904 サメトロ
ユーザー 👑 H20H20
提出日時 2021-08-03 10:37:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 932 bytes
コンパイル時間 2,066 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 76,344 KB
最終ジャッジ日時 2023-10-14 21:07:15
合計ジャッジ時間 4,743 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,432 KB
testcase_01 AC 89 ms
71,652 KB
testcase_02 AC 89 ms
71,584 KB
testcase_03 AC 89 ms
71,544 KB
testcase_04 AC 87 ms
71,652 KB
testcase_05 AC 85 ms
71,428 KB
testcase_06 AC 87 ms
71,520 KB
testcase_07 AC 87 ms
71,740 KB
testcase_08 AC 88 ms
71,544 KB
testcase_09 WA -
testcase_10 AC 88 ms
71,440 KB
testcase_11 AC 88 ms
71,432 KB
testcase_12 AC 85 ms
71,584 KB
testcase_13 AC 86 ms
71,536 KB
testcase_14 AC 86 ms
71,672 KB
testcase_15 AC 86 ms
71,672 KB
testcase_16 AC 94 ms
76,100 KB
testcase_17 AC 86 ms
71,764 KB
testcase_18 AC 87 ms
71,496 KB
testcase_19 AC 86 ms
71,380 KB
testcase_20 AC 87 ms
71,432 KB
testcase_21 AC 88 ms
71,460 KB
testcase_22 AC 88 ms
71,380 KB
testcase_23 AC 88 ms
71,748 KB
testcase_24 AC 86 ms
71,496 KB
testcase_25 AC 86 ms
71,800 KB
testcase_26 AC 93 ms
76,344 KB
testcase_27 AC 96 ms
76,104 KB
testcase_28 AC 85 ms
71,664 KB
testcase_29 AC 92 ms
76,300 KB
testcase_30 AC 85 ms
71,376 KB
testcase_31 AC 85 ms
71,432 KB
testcase_32 AC 86 ms
71,584 KB
testcase_33 AC 87 ms
71,752 KB
testcase_34 AC 84 ms
71,560 KB
testcase_35 AC 86 ms
71,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

0