結果

問題 No.1391 ±1 Abs Sum
ユーザー shotoyooshotoyoo
提出日時 2021-02-12 22:07:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 593 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 127,924 KB
最終ジャッジ日時 2023-09-27 04:14:59
合計ジャッジ時間 7,216 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,556 KB
testcase_01 AC 68 ms
71,340 KB
testcase_02 AC 69 ms
71,180 KB
testcase_03 AC 69 ms
71,364 KB
testcase_04 AC 68 ms
71,168 KB
testcase_05 AC 69 ms
71,380 KB
testcase_06 AC 69 ms
71,284 KB
testcase_07 AC 70 ms
71,348 KB
testcase_08 WA -
testcase_09 AC 71 ms
71,260 KB
testcase_10 AC 71 ms
71,344 KB
testcase_11 AC 170 ms
127,924 KB
testcase_12 AC 144 ms
101,776 KB
testcase_13 AC 176 ms
124,272 KB
testcase_14 AC 131 ms
104,868 KB
testcase_15 AC 139 ms
105,196 KB
testcase_16 AC 137 ms
101,964 KB
testcase_17 AC 148 ms
106,752 KB
testcase_18 AC 149 ms
111,316 KB
testcase_19 AC 151 ms
106,668 KB
testcase_20 AC 178 ms
126,444 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 144 ms
116,360 KB
testcase_24 AC 144 ms
115,796 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 151 ms
116,772 KB
testcase_28 WA -
testcase_29 AC 143 ms
114,536 KB
testcase_30 WA -
testcase_31 AC 155 ms
119,476 KB
testcase_32 AC 117 ms
101,536 KB
testcase_33 AC 123 ms
107,180 KB
testcase_34 AC 134 ms
111,992 KB
testcase_35 AC 72 ms
71,444 KB
testcase_36 AC 136 ms
115,980 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-1] - 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