結果

問題 No.1687 What the Heck?
ユーザー aaaaaaaaaa2230
提出日時 2021-09-24 21:59:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 383 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,028 KB
実行使用メモリ 105,784 KB
最終ジャッジ日時 2024-07-05 10:34:30
合計ジャッジ時間 2,222 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
P = list(map(int,input().split()))
ma = n
ans = 0
use = [0]*(n+1)
score = 0
for i in range(n)[::-1]:
    p = P[i]
    if p > ma:
        ans = max(ans,score-i-1+i*(i+1)//2)
        break
    elif p == ma:
        ans = max(ans,score-i-1+i*(i+1)//2)
        use[p] = 1
    else:
        score += i+1
        use[p+1] = 1
    while use[ma]:
        ma -= 1
print(ans)
0