結果

問題 No.615 集合に分けよう
ユーザー yomo3yomo3
提出日時 2020-03-23 00:58:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 10,748 KB
実行使用メモリ 17,752 KB
最終ジャッジ日時 2023-08-27 01:17:04
合計ジャッジ時間 3,352 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,880 KB
testcase_01 AC 16 ms
7,948 KB
testcase_02 AC 16 ms
7,776 KB
testcase_03 AC 17 ms
7,780 KB
testcase_04 AC 17 ms
7,896 KB
testcase_05 AC 17 ms
7,804 KB
testcase_06 AC 17 ms
7,776 KB
testcase_07 AC 16 ms
7,796 KB
testcase_08 AC 17 ms
7,836 KB
testcase_09 AC 17 ms
7,732 KB
testcase_10 AC 17 ms
7,856 KB
testcase_11 AC 17 ms
7,804 KB
testcase_12 AC 16 ms
7,776 KB
testcase_13 AC 17 ms
8,208 KB
testcase_14 AC 18 ms
8,204 KB
testcase_15 AC 30 ms
9,952 KB
testcase_16 AC 137 ms
17,648 KB
testcase_17 AC 91 ms
17,660 KB
testcase_18 AC 92 ms
17,612 KB
testcase_19 AC 91 ms
17,752 KB
testcase_20 AC 100 ms
17,684 KB
testcase_21 AC 114 ms
17,552 KB
testcase_22 AC 135 ms
17,624 KB
testcase_23 AC 50 ms
13,984 KB
testcase_24 AC 78 ms
17,356 KB
testcase_25 AC 16 ms
7,840 KB
testcase_26 AC 16 ms
7,780 KB
testcase_27 AC 42 ms
14,012 KB
testcase_28 AC 42 ms
14,040 KB
testcase_29 AC 49 ms
15,600 KB
testcase_30 AC 54 ms
15,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter

N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
A.sort()
d = [A[i + 1] - A[i] for i in range(N - 1)]
d = list(zip(d, range(N - 1)))
d.sort(reverse=True, key=itemgetter(0))
s = 0
for i in range(K):
    e = -1 if i == K - 1 else d[i][1]
    ans += A[e] - A[s]
    s = e + 1
print(ans)
0