結果

問題 No.1391 ±1 Abs Sum
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-02-12 22:18:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 430 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 108,788 KB
最終ジャッジ日時 2023-09-27 04:42:11
合計ジャッジ時間 7,118 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,516 KB
testcase_01 AC 77 ms
71,460 KB
testcase_02 AC 75 ms
71,264 KB
testcase_03 AC 79 ms
71,128 KB
testcase_04 AC 80 ms
71,564 KB
testcase_05 WA -
testcase_06 AC 78 ms
71,520 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 124 ms
96,136 KB
testcase_15 AC 128 ms
97,672 KB
testcase_16 AC 138 ms
104,292 KB
testcase_17 AC 136 ms
100,660 KB
testcase_18 AC 153 ms
104,564 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 160 ms
108,268 KB
testcase_32 AC 121 ms
93,404 KB
testcase_33 AC 127 ms
98,076 KB
testcase_34 WA -
testcase_35 AC 80 ms
71,432 KB
testcase_36 AC 170 ms
108,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ans = 10 ** 18
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [1] * k + [-1] * (n - k)
x = a[0]
ans = min(ans, sum(b[i] * abs(x - a[i]) for i in range(n)))
x = a[-1]
ans = min(ans, sum(b[i] * abs(x - a[i]) for i in range(n)))
b = [-1] * (n - k) + [1] * k
x = a[0]
ans = min(ans, sum(b[i] * abs(x - a[i]) for i in range(n)))
x = a[-1]
ans = min(ans, sum(b[i] * abs(x - a[i]) for i in range(n)))
print(ans)
0