結果

問題 No.1460 Max of Min
ユーザー lam6er
提出日時 2025-04-16 00:10:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,460 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 76,692 KB
最終ジャッジ日時 2025-04-16 00:12:07
合計ジャッジ時間 9,165 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 WA * 63
権限があれば一括ダウンロードができます

ソースコード

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
    
    M = max(B)
    current = deque(A, maxlen=K)
    
    # Simulate up to 2*K steps beyond the initial K elements
    max_steps = 2 * K
    for step in range(K, max_steps + 1):
        if step > N:
            break
        # Check if current state can produce M
        has_condition = False
        for m in range(K):
            if B[m] == M and current[m] >= M:
                has_condition = True
                break
        if has_condition:
            print(M)
            return
        # Compute next value
        next_val = -float('inf')
        for m in range(K):
            val = min(current[m], B[m])
            if val > next_val:
                next_val = val
        current.append(next_val)
        if step == N:
            print(next_val)
            return
    
    # After max_steps, check if all elements are <= B
    all_leq = True
    for m in range(K):
        if current[m] > B[m]:
            all_leq = False
            break
    if all_leq:
        X = max(current)
        print(X)
    else:
        # If not handled, return the last computed value (may not be correct for some cases)
        print(current[-1])
    
if __name__ == "__main__":
    main()
0