結果

問題 No.808 Kaiten Sushi?
ユーザー tktk_snsn
提出日時 2021-02-06 12:00:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 109,596 KB
最終ジャッジ日時 2024-07-02 18:53:22
合計ジャッジ時間 6,167 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

def merge(x, y):
    x.reverse()
    y.reverse()
    res = []
    while x and y:
        if x[-1] < y[-1]:
            res.append(x.pop())
        else:
            res.append(~y.pop())
    while x:
        res.append(x.pop())
    while y:
        res.append(~y.pop())
    return res


N, L = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = merge(A[:], B[:])

p = 0
D = [-1] * (2 * N)
for i, c in enumerate(C):
    if c >= 0:
        p += 1
    else:
        p -= 1
    D[i] = p

mx = max(D)
mn = min(D)

if mx == 0:
    ans = L * (mx - mn) + B[0]
else:
    D = [d - mn for d in D]
    loop = max(D) - 1
    walk = -1
    for c, d in zip(C, D):
        if c < 0 and d == loop:
            walk = ~c
    ans = L*loop + walk

print(ans)
0