結果

問題 No.1460 Max of Min
ユーザー lam6er
提出日時 2025-03-20 20:43:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 784 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 77,452 KB
最終ジャッジ日時 2025-03-20 20:43:19
合計ジャッジ時間 6,521 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 85
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    K, N = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    
    if N < K:
        print(A[N])
        return
    
    window = deque(A)
    for _ in range(K, N+1):
        next_val = max(min(window[j], B[j]) for j in range(K))
        window.popleft()
        window.append(next_val)
        # Check if all elements in the window are the same
        all_same = True
        first = window[0]
        for val in window:
            if val != first:
                all_same = False
                break
        if all_same:
            print(first)
            return
    print(window[-1])

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