結果

問題 No.1687 What the Heck?
ユーザー O2MTO2MT
提出日時 2021-09-29 14:43:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 626 ms / 2,000 ms
コード長 342 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 109,980 KB
最終ジャッジ日時 2023-09-23 11:17:29
合計ジャッジ時間 7,423 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,576 KB
testcase_01 AC 71 ms
71,204 KB
testcase_02 AC 71 ms
71,624 KB
testcase_03 AC 71 ms
71,336 KB
testcase_04 AC 71 ms
71,380 KB
testcase_05 AC 74 ms
71,416 KB
testcase_06 AC 74 ms
71,416 KB
testcase_07 AC 242 ms
87,124 KB
testcase_08 AC 323 ms
93,044 KB
testcase_09 AC 244 ms
87,196 KB
testcase_10 AC 180 ms
84,032 KB
testcase_11 AC 189 ms
84,464 KB
testcase_12 AC 615 ms
109,660 KB
testcase_13 AC 613 ms
109,660 KB
testcase_14 AC 608 ms
109,816 KB
testcase_15 AC 605 ms
109,844 KB
testcase_16 AC 600 ms
109,740 KB
testcase_17 AC 106 ms
77,728 KB
testcase_18 AC 626 ms
109,980 KB
testcase_19 AC 80 ms
76,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
P = list(map(int,input().split()))

if len(P) == 1:
  print(0)
  exit()

A = [(P[i],i+1) for i in range(N)]
A.sort(reverse=True)
ac_A = [A[0][1]]

for i in range(1,N):
  ac_A.append(ac_A[-1]+A[i][1])

ans = N*(N+1)//2
num = 2*A[0][1]

for i in range(1,N):
  num = min(num,ac_A[i-1]+2*A[i][1])

ans = max(0,ans-num)
print(ans)
0