結果
| 問題 | No.1687 What the Heck? | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 14:04:19 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 379 bytes | 
| コンパイル時間 | 203 ms | 
| コンパイル使用メモリ | 82,240 KB | 
| 実行使用メモリ | 110,956 KB | 
| 最終ジャッジ日時 | 2025-06-12 14:04:45 | 
| 合計ジャッジ時間 | 2,528 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 1 WA * 17 | 
ソースコード
n = int(input())
p = list(map(int, input().split()))
rounds = sorted([(p[i], i + 1) for i in range(n)], key=lambda x: -x[1])
a = sorted(range(1, n + 1), reverse=True)
pointer = 0
ans = 0
for pi, i in rounds:
    if pointer < len(a) and a[pointer] > pi:
        ans += i
        pointer += 1
    else:
        if a and a[-1] < pi:
            ans -= i
        a.pop()
print(ans)
            
            
            
        