結果

問題 No.1391 ±1 Abs Sum
ユーザー nephrologistnephrologist
提出日時 2021-02-12 23:00:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 437 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 115,780 KB
最終ジャッジ日時 2023-09-27 06:08:09
合計ジャッジ時間 6,656 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,280 KB
testcase_01 AC 72 ms
71,484 KB
testcase_02 AC 71 ms
71,568 KB
testcase_03 AC 72 ms
71,432 KB
testcase_04 AC 69 ms
71,324 KB
testcase_05 WA -
testcase_06 AC 72 ms
71,612 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 111 ms
96,116 KB
testcase_15 AC 117 ms
97,464 KB
testcase_16 AC 124 ms
102,364 KB
testcase_17 AC 121 ms
100,216 KB
testcase_18 AC 141 ms
110,748 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 146 ms
114,904 KB
testcase_32 AC 110 ms
96,540 KB
testcase_33 AC 114 ms
97,612 KB
testcase_34 AC 147 ms
114,364 KB
testcase_35 AC 70 ms
71,180 KB
testcase_36 AC 152 ms
115,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
A = list(map(int, input().split()))

med = n // 2
Am1 = A[med]
Am2 = A[med - 1]
A0 = [abs(a - Am2) for a in A]
A1 = [abs(a - Am1) for a in A]
A1.sort()
A2 = [abs(a - A[0]) for a in A]
A2.sort()
A3 = [abs(a - A[-1]) for a in A]
A3.sort()
ans0 = sum(A0[:k]) - sum(A0[k:])
ans1 = sum(A1[:k]) - sum(A1[k:])
ans2 = sum(A2[:k]) - sum(A2[k:])
ans3 = sum(A3[:k]) - sum(A3[k:])
print(min(ans0, ans1, ans2, ans3))
0