結果

問題 No.1391 ±1 Abs Sum
ユーザー shotoyooshotoyoo
提出日時 2021-02-12 22:09:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 128,016 KB
最終ジャッジ日時 2023-09-27 04:22:43
合計ジャッジ時間 6,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,360 KB
testcase_01 AC 67 ms
71,016 KB
testcase_02 AC 67 ms
71,292 KB
testcase_03 AC 68 ms
71,104 KB
testcase_04 AC 67 ms
70,836 KB
testcase_05 AC 66 ms
70,832 KB
testcase_06 AC 68 ms
71,236 KB
testcase_07 AC 67 ms
71,048 KB
testcase_08 AC 69 ms
71,264 KB
testcase_09 AC 68 ms
70,836 KB
testcase_10 AC 67 ms
71,236 KB
testcase_11 AC 164 ms
128,016 KB
testcase_12 AC 144 ms
101,964 KB
testcase_13 AC 169 ms
124,196 KB
testcase_14 AC 125 ms
104,848 KB
testcase_15 AC 135 ms
104,968 KB
testcase_16 AC 142 ms
102,020 KB
testcase_17 AC 137 ms
106,512 KB
testcase_18 AC 144 ms
111,152 KB
testcase_19 AC 139 ms
106,548 KB
testcase_20 AC 168 ms
126,204 KB
testcase_21 AC 137 ms
111,404 KB
testcase_22 AC 135 ms
111,308 KB
testcase_23 AC 145 ms
116,240 KB
testcase_24 AC 139 ms
115,852 KB
testcase_25 AC 144 ms
115,744 KB
testcase_26 AC 145 ms
116,108 KB
testcase_27 AC 144 ms
116,980 KB
testcase_28 AC 149 ms
117,332 KB
testcase_29 AC 135 ms
114,276 KB
testcase_30 AC 164 ms
122,672 KB
testcase_31 AC 152 ms
119,536 KB
testcase_32 AC 104 ms
99,592 KB
testcase_33 AC 111 ms
105,264 KB
testcase_34 AC 129 ms
111,768 KB
testcase_35 AC 73 ms
71,256 KB
testcase_36 AC 131 ms
115,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")

n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
cum = [0]
v = 0
for i in range(n):
    v += a[i]
    cum.append(v)
l = 0
ans = float("inf")
for i in range(n):
    x = a[i]
    while l<i and l<n-k and x - a[l] > a[k+l] - x:
        l += 1
    val = cum[l] - (cum[i] - cum[l]) + (cum[k+l] - cum[i]) - (cum[n] - cum[k+l])
    ans = min(ans, val + x * (n - 2*k - 4*l + 2*i))
#     print(i,l,val,x * (n - 2*k - 4*l + 2*i))
print(ans)
0