結果

問題 No.615 集合に分けよう
ユーザー Mr.FukuMr.Fuku
提出日時 2018-07-11 23:07:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 11,936 KB
実行使用メモリ 20,060 KB
最終ジャッジ日時 2023-10-22 01:26:49
合計ジャッジ時間 3,936 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,076 KB
testcase_01 AC 30 ms
10,076 KB
testcase_02 AC 29 ms
10,076 KB
testcase_03 AC 29 ms
10,076 KB
testcase_04 AC 29 ms
10,076 KB
testcase_05 AC 29 ms
10,076 KB
testcase_06 AC 29 ms
10,076 KB
testcase_07 AC 29 ms
10,080 KB
testcase_08 AC 29 ms
10,080 KB
testcase_09 AC 29 ms
10,080 KB
testcase_10 AC 29 ms
10,080 KB
testcase_11 AC 29 ms
10,080 KB
testcase_12 AC 29 ms
10,080 KB
testcase_13 AC 30 ms
10,168 KB
testcase_14 AC 31 ms
10,280 KB
testcase_15 AC 50 ms
11,908 KB
testcase_16 AC 64 ms
15,700 KB
testcase_17 AC 157 ms
19,532 KB
testcase_18 AC 159 ms
19,532 KB
testcase_19 AC 162 ms
19,532 KB
testcase_20 AC 175 ms
19,532 KB
testcase_21 AC 197 ms
19,796 KB
testcase_22 AC 226 ms
20,060 KB
testcase_23 AC 81 ms
16,420 KB
testcase_24 AC 162 ms
19,564 KB
testcase_25 AC 29 ms
10,076 KB
testcase_26 AC 31 ms
10,076 KB
testcase_27 AC 70 ms
16,120 KB
testcase_28 AC 68 ms
16,120 KB
testcase_29 AC 77 ms
17,716 KB
testcase_30 AC 82 ms
17,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

n,k = map(int,input().split())
lst = list(map(int,input().split()))
lst.sort()
indx_lst = []

if n==k:
    print(0)
else:
    for i in range(n-1):
        x = lst[i+1] - lst[i]
        indx_lst.append([x,i])
        
    indx_lst.sort()
    ans_lst = []
    
    for i in range(1,k):
        ans_lst.append(indx_lst[-i][1])
    
    ans_lst.sort()
    ans_lst.append(n-1)
    
    indx = 0
    total = 0
    
    for i in range(k):
        total += lst[ans_lst[i]] - lst[indx]
        indx = ans_lst[i] + 1
    print(total)
0