結果

問題 No.2036 Max Middle
ユーザー gew1fw
提出日時 2025-06-12 16:20:52
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 743 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 106,796 KB
最終ジャッジ日時 2025-06-12 16:21:17
合計ジャッジ時間 4,278 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

def max_operations():
    import sys
    input = sys.stdin.read().split()
    n = int(input[0])
    a = list(map(int, input[1:n+1]))
    
    count = 0
    i = 0
    while i < n-2:
        if a[i] < a[i+1] and a[i+1] > a[i+2]:
            # Perform the operation
            new_val = min(a[i], a[i+2]) - 1
            a[i+1] = new_val
            count += 1
            # After operation, check if i can still be a peak or if i-1 became a peak
            # We might need to check previous indices
            if i > 0 and a[i-1] < a[i] and a[i] > a[i+1]:
                i = max(i-1, 0)
                continue
            else:
                i = max(i-1, 0)
                continue
        i += 1
    
    print(count)

max_operations()
0