結果

問題 No.1460 Max of Min
ユーザー lam6er
提出日時 2025-04-16 00:06:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 84,524 KB
最終ジャッジ日時 2025-04-16 00:08:06
合計ジャッジ時間 4,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 3 TLE * 1 -- * 83
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    K, N = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    M = max(B)
    
    if N < K:
        print(A[N])
        return
    
    if any(a >= M for a in A):
        print(M)
        return
    
    current = A.copy()
    max_steps = K * K + K  # Arbitrary large enough steps to detect stabilization
    for i in range(K, max_steps + 1):
        next_val = max(min(current[j], B[j]) for j in range(K))
        if next_val == M:
            print(M)
            return
        current.pop(0)
        current.append(next_val)
        if all(x == current[0] for x in current):
            x = current[0]
            print(x if x <= M else M)
            return
        if i == N:
            print(next_val)
            return
    
    # If not stabilized, which shouldn't happen for the problem's constraints
    print(current[-1])

if __name__ == "__main__":
    main()
0