結果

問題 No.1391 ±1 Abs Sum
ユーザー nephrologistnephrologist
提出日時 2021-02-12 23:01:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 447 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 117,032 KB
最終ジャッジ日時 2023-09-27 06:11:46
合計ジャッジ時間 5,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,464 KB
testcase_01 AC 65 ms
71,148 KB
testcase_02 AC 64 ms
71,156 KB
testcase_03 AC 61 ms
71,480 KB
testcase_04 AC 61 ms
71,388 KB
testcase_05 WA -
testcase_06 AC 62 ms
71,192 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 103 ms
96,864 KB
testcase_15 AC 103 ms
98,008 KB
testcase_16 AC 117 ms
102,220 KB
testcase_17 AC 114 ms
100,648 KB
testcase_18 AC 129 ms
111,712 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 141 ms
116,480 KB
testcase_32 AC 99 ms
95,708 KB
testcase_33 AC 104 ms
98,032 KB
testcase_34 AC 135 ms
115,620 KB
testcase_35 AC 62 ms
71,332 KB
testcase_36 AC 131 ms
116,020 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]
A0.sort()
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