結果

問題 No.1687 What the Heck?
ユーザー gew1fw
提出日時 2025-06-12 21:36:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 619 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 109,588 KB
最終ジャッジ日時 2025-06-12 21:39:23
合計ジャッジ時間 2,999 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    N = int(sys.stdin.readline())
    P = list(map(int, sys.stdin.readline().split()))
    
    sorted_rounds = sorted(range(1, N+1), key=lambda x: -x)
    available_S = deque(range(1, N+1))
    
    total = 0
    
    for i in sorted_rounds:
        p_i = P[i-1]
        if available_S and available_S[-1] > p_i:
            total += i
            available_S.pop()
        else:
            if available_S:
                s = available_S.popleft()
                if s < p_i:
                    total -= i
    print(total)

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