結果
| 問題 | No.615 集合に分けよう | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-15 00:16:55 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 93 ms / 2,000 ms | 
| コード長 | 399 bytes | 
| コンパイル時間 | 1,070 ms | 
| コンパイル使用メモリ | 6,948 KB | 
| 実行使用メモリ | 14,100 KB | 
| 最終ジャッジ日時 | 2024-12-14 13:46:34 | 
| 合計ジャッジ時間 | 2,573 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 26 | 
ソースコード
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# †
from itertools import tee
# s -> (s0,s1), (s1,s2), (s2,s3), ...
def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)
N, K = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
difs = [q-p for p, q in pairwise(a)]
difs.sort()
res = a[-1] - a[0]
if K > 1:
    res -= sum(difs[-K+1:])
print res
            
            
            
        