結果
問題 |
No.615 集合に分けよう
|
ユーザー |
|
提出日時 | 2017-12-16 03:06:03 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 187 ms / 2,000 ms |
コード長 | 559 bytes |
コンパイル時間 | 98 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 21,328 KB |
最終ジャッジ日時 | 2024-12-14 17:01:41 |
合計ジャッジ時間 | 3,027 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
def main(): N, K = map(int, input().split()) if N == K: print(0) exit() A = tuple(map(int, input().split())) if K == 1: print(max(A) - min(A)) exit() a = sorted(A) slice_ = [0] * (N - 1) for i in range(1, N): slice_[i-1] = (a[i] - a[i-1], i) slice_.sort(reverse=True) splt = sorted(slice_[:K-1], key=lambda x: x[1]) s = 0 total = 0 for _, e in splt: total += max(a[s:e]) - min(a[s:e]) s = e total += max(a[s:]) - min(a[s:]) print(total) main()