結果

問題 No.1460 Max of Min
ユーザー Shinya Fujita
提出日時 2024-12-27 15:48:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,461 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 135,468 KB
最終ジャッジ日時 2024-12-27 15:49:41
合計ジャッジ時間 43,904 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 91
権限があれば一括ダウンロードができます

ソースコード

diff #

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


def calc():
    res = -10**18
    for i in range(1, K+1):
        res = max(res, min(A[-i], B[-i]))
    return res


for _ in range(K):
    A.append(calc())


if N <= len(A)-1:
    print(A[N])
    quit()


from heapq import heappop, heappush

def check(x):
    AA = [a>=x for a in A]
    T = []
    for i, b in enumerate(B):
        if b >= x:
            T.append(K - i)
    
    if len(T) == 0:
        return False
    
    t0 = T[0]
    Min = [-1] * t0
    hq = []
    for i in range(K, 2*K):
        if AA[i]:
            heappush(hq, (i, i%t0))
    while hq:
        i, pos = heappop(hq)
        if Min[pos] != -1:
            continue
        Min[pos] = i
        for t in T:
            ii = (i+t) % t0
            if Min[ii] == -1:
                heappush(hq, (i+t, ii))
    return 0 <= Min[N%t0] <= N


S = sorted(set(A + B))
if check(S[-1]):
    print(S[-1])
    quit()

ok = 0
ng = len(S) - 1
while ok+1 < ng:
    mid = (ok + ng) // 2
    if check(S[mid]):
        ok = mid
    else:
        ng = mid

print(S[ok])

0