結果

問題 No.1391 ±1 Abs Sum
ユーザー 👑 rin204rin204
提出日時 2024-05-07 21:40:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 461 bytes
コンパイル時間 885 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 121,040 KB
最終ジャッジ日時 2024-05-07 21:40:14
合計ジャッジ時間 6,606 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 AC 39 ms
51,968 KB
testcase_02 AC 39 ms
51,840 KB
testcase_03 AC 39 ms
52,096 KB
testcase_04 AC 38 ms
51,968 KB
testcase_05 AC 38 ms
52,096 KB
testcase_06 AC 39 ms
51,840 KB
testcase_07 AC 38 ms
51,968 KB
testcase_08 AC 40 ms
52,224 KB
testcase_09 AC 40 ms
51,712 KB
testcase_10 AC 40 ms
52,224 KB
testcase_11 AC 160 ms
121,040 KB
testcase_12 AC 129 ms
110,976 KB
testcase_13 AC 141 ms
104,704 KB
testcase_14 AC 105 ms
101,820 KB
testcase_15 AC 116 ms
104,704 KB
testcase_16 AC 128 ms
110,336 KB
testcase_17 AC 120 ms
107,648 KB
testcase_18 AC 123 ms
104,320 KB
testcase_19 AC 119 ms
111,616 KB
testcase_20 AC 165 ms
120,232 KB
testcase_21 AC 121 ms
110,336 KB
testcase_22 AC 120 ms
110,336 KB
testcase_23 AC 128 ms
115,456 KB
testcase_24 AC 122 ms
114,688 KB
testcase_25 AC 126 ms
115,080 KB
testcase_26 AC 126 ms
115,456 KB
testcase_27 AC 120 ms
109,824 KB
testcase_28 AC 123 ms
110,464 KB
testcase_29 AC 139 ms
113,520 KB
testcase_30 AC 134 ms
112,512 KB
testcase_31 AC 136 ms
116,440 KB
testcase_32 AC 82 ms
95,488 KB
testcase_33 AC 88 ms
101,888 KB
testcase_34 AC 105 ms
107,136 KB
testcase_35 AC 37 ms
51,712 KB
testcase_36 AC 122 ms
112,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
A = list(map(int, input().split()))
cum = [0]
for a in A:
    cum.append(cum[-1] + a)

ans = 1 << 60
r = k
for i, a in enumerate(A):
    while r < n and A[r] - A[i] < A[i] - A[r - k]:
        r += 1

    l = r - k
    tot = 0
    tot -= (cum[n] - cum[r]) - a * (n - r)
    tot += (cum[r] - cum[i]) - a * (r - i)
    tot -= (cum[i] - cum[l]) - a * (i - l)
    tot += (cum[l] - cum[0]) - a * l
    ans = min(ans, tot)

print(ans)
0