結果

問題 No.1391 ±1 Abs Sum
ユーザー KudeKude
提出日時 2021-02-12 21:58:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 433 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 108,456 KB
最終ジャッジ日時 2023-09-27 03:54:54
合計ジャッジ時間 6,369 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,440 KB
testcase_01 AC 71 ms
71,396 KB
testcase_02 AC 71 ms
71,408 KB
testcase_03 AC 71 ms
71,288 KB
testcase_04 AC 71 ms
71,112 KB
testcase_05 AC 73 ms
71,176 KB
testcase_06 AC 72 ms
71,368 KB
testcase_07 AC 72 ms
71,248 KB
testcase_08 AC 71 ms
71,404 KB
testcase_09 AC 71 ms
71,108 KB
testcase_10 AC 71 ms
71,436 KB
testcase_11 AC 163 ms
108,456 KB
testcase_12 AC 144 ms
102,456 KB
testcase_13 AC 161 ms
106,284 KB
testcase_14 AC 122 ms
94,668 KB
testcase_15 AC 126 ms
96,896 KB
testcase_16 AC 139 ms
102,092 KB
testcase_17 AC 132 ms
99,508 KB
testcase_18 AC 147 ms
99,916 KB
testcase_19 AC 133 ms
99,336 KB
testcase_20 AC 162 ms
107,856 KB
testcase_21 AC 132 ms
102,024 KB
testcase_22 AC 133 ms
102,056 KB
testcase_23 AC 137 ms
105,600 KB
testcase_24 AC 134 ms
105,004 KB
testcase_25 AC 137 ms
105,020 KB
testcase_26 AC 139 ms
105,624 KB
testcase_27 AC 129 ms
98,868 KB
testcase_28 AC 132 ms
99,504 KB
testcase_29 AC 133 ms
104,824 KB
testcase_30 AC 133 ms
98,948 KB
testcase_31 AC 155 ms
105,020 KB
testcase_32 AC 109 ms
92,604 KB
testcase_33 AC 112 ms
96,604 KB
testcase_34 AC 133 ms
101,428 KB
testcase_35 AC 72 ms
71,040 KB
testcase_36 AC 135 ms
103,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
k = n - k
a = list(map(int, input().split()))
now = sum(x - a[0] for x in a[:n - k]) - sum(x - a[0] for x in a[n - k: n])
ans = now
l = 0
r = n - k
for i in range(1, n):
    x = a[i]
    now += (a[i] - a[i-1]) * (-l + i-l - (r-i) + n-r)
    while l < i and r < n and x - a[l] > a[r] - x:
        now += -2 * (x - a[l]) + 2 * (a[r] - x)
        l += 1
        r += 1
    ans = min(ans, now)
print(ans)
0