結果

問題 No.1391 ±1 Abs Sum
ユーザー so4649so4649
提出日時 2021-02-12 22:05:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 646 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 86,728 KB
実行使用メモリ 111,300 KB
最終ジャッジ日時 2023-09-27 04:07:47
合計ジャッジ時間 8,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,240 KB
testcase_01 AC 73 ms
71,296 KB
testcase_02 AC 70 ms
71,332 KB
testcase_03 AC 71 ms
71,216 KB
testcase_04 AC 71 ms
71,068 KB
testcase_05 WA -
testcase_06 AC 72 ms
71,428 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 115 ms
96,336 KB
testcase_15 AC 116 ms
98,892 KB
testcase_16 AC 127 ms
105,420 KB
testcase_17 AC 123 ms
102,268 KB
testcase_18 AC 143 ms
107,152 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 148 ms
110,720 KB
testcase_32 AC 109 ms
96,780 KB
testcase_33 AC 115 ms
101,796 KB
testcase_34 WA -
testcase_35 AC 73 ms
70,928 KB
testcase_36 AC 147 ms
111,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int,input().split())
a = list(map(int,input().split()))

k = n-k

ans = 10**15

b = [1]*(n-k)+[-1]*k
ruiseki = [0]*(n+1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i]+b[i]
base = 0
while base+1 < n and ruiseki[base+1] < (n-2*k+1)//2:
    base += 1
left = sum(a[i]-a[base] for i in range(n-k))+sum(a[base]-a[i] for i in range(n-k,n))

b = [-1]*k+[1]*(n-k)
ruiseki = [0]*(n+1)
for i in range(n):
    ruiseki[i+1] = ruiseki[i]+b[i]
base = n-1
while 0 < base and ruiseki[n]-ruiseki[base] < (n-2*k+1)//2:
    base -= 1
right = sum(a[i]-a[base] for i in range(k))+sum(a[base]-a[i] for i in range(k,n))

ans = min(ans,left,right)
print(ans)
0