結果

問題 No.1391 ±1 Abs Sum
ユーザー nephrologistnephrologist
提出日時 2021-02-12 22:54:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 464 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 109,224 KB
最終ジャッジ日時 2023-09-27 05:55:46
合計ジャッジ時間 6,533 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,156 KB
testcase_01 AC 74 ms
71,480 KB
testcase_02 AC 70 ms
71,500 KB
testcase_03 AC 71 ms
71,712 KB
testcase_04 AC 70 ms
71,428 KB
testcase_05 WA -
testcase_06 AC 70 ms
71,152 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 113 ms
98,296 KB
testcase_15 AC 119 ms
100,188 KB
testcase_16 AC 122 ms
102,060 KB
testcase_17 AC 122 ms
102,408 KB
testcase_18 AC 137 ms
104,304 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 147 ms
107,732 KB
testcase_32 AC 105 ms
95,416 KB
testcase_33 AC 114 ms
100,448 KB
testcase_34 AC 140 ms
107,168 KB
testcase_35 AC 74 ms
71,652 KB
testcase_36 AC 146 ms
109,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

med = n // 2
Am = A[med]
A1 = [abs(a - Am) for a in A]
A1.sort(reverse=True)
A2 = [abs(a - A[0]) for a in A]
A2 = A2[::-1]
A3 = [abs(a - A[-1]) for a in A]

ans1, ans2, ans3 = 0, 0, 0

for i in range(n):
    if i < n - k:
        ans1 -= A1[i]
        ans2 -= A2[i]
        ans3 -= A3[i]
    else:
        ans1 += A1[i]
        ans2 += A2[i]
        ans3 += A3[i]
print(min(ans1, ans2, ans3))

0