結果

問題 No.1391 ±1 Abs Sum
ユーザー H3PO4H3PO4
提出日時 2021-02-12 22:15:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 30,852 KB
最終ジャッジ日時 2023-09-27 04:32:45
合計ジャッジ時間 9,581 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,904 KB
testcase_01 AC 13 ms
7,796 KB
testcase_02 AC 13 ms
7,848 KB
testcase_03 AC 14 ms
7,848 KB
testcase_04 AC 15 ms
7,852 KB
testcase_05 AC 14 ms
7,848 KB
testcase_06 AC 13 ms
7,892 KB
testcase_07 AC 14 ms
7,848 KB
testcase_08 AC 13 ms
7,860 KB
testcase_09 AC 14 ms
7,976 KB
testcase_10 AC 14 ms
7,792 KB
testcase_11 AC 399 ms
30,260 KB
testcase_12 AC 298 ms
24,868 KB
testcase_13 AC 366 ms
28,616 KB
testcase_14 AC 274 ms
20,256 KB
testcase_15 AC 299 ms
21,232 KB
testcase_16 AC 361 ms
24,748 KB
testcase_17 AC 322 ms
22,456 KB
testcase_18 AC 446 ms
27,760 KB
testcase_19 AC 246 ms
22,452 KB
testcase_20 AC 399 ms
29,688 KB
testcase_21 AC 271 ms
26,680 KB
testcase_22 AC 258 ms
26,648 KB
testcase_23 AC 303 ms
30,616 KB
testcase_24 AC 289 ms
26,724 KB
testcase_25 AC 311 ms
28,260 KB
testcase_26 AC 299 ms
29,516 KB
testcase_27 AC 201 ms
22,504 KB
testcase_28 AC 215 ms
22,132 KB
testcase_29 AC 271 ms
26,612 KB
testcase_30 AC 237 ms
23,740 KB
testcase_31 AC 436 ms
30,168 KB
testcase_32 AC 259 ms
19,424 KB
testcase_33 AC 291 ms
21,232 KB
testcase_34 AC 279 ms
29,208 KB
testcase_35 AC 14 ms
7,768 KB
testcase_36 AC 294 ms
30,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
A = tuple(map(int, input().split()))

l, r = 0, K
A0 = A[0]
plus, minus = sum(a - A0 for a in A[:K]), sum(a - A0 for a in A[K:])
ans = plus - minus
for i in range(1, N):
    x = A[i]
    diff = A[i] - A[i - 1]
    plus += diff * (2 * i - l - r)
    minus += diff * (l + r - N)
    while r < N and (arx := (A[r] - x)) < (alx := (x - A[l])):
        plus += arx - alx
        minus += alx - arx
        r += 1
        l += 1
    ans = min(plus - minus, ans)
print(ans)
0