結果
| 問題 |
No.615 集合に分けよう
|
| コンテスト | |
| ユーザー |
Mr.Fuku
|
| 提出日時 | 2018-07-11 23:07:00 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 227 ms / 2,000 ms |
| コード長 | 558 bytes |
| コンパイル時間 | 165 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 20,620 KB |
| 最終ジャッジ日時 | 2024-09-22 02:47:12 |
| 合計ジャッジ時間 | 4,260 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 26 |
ソースコード
# 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)
Mr.Fuku