結果

問題 No.615 集合に分けよう
ユーザー yuppe19 😺yuppe19 😺
提出日時 2017-12-15 00:16:55
言語 Python2
(2.7.18)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 399 bytes
コンパイル時間 585 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 14,224 KB
最終ジャッジ日時 2024-05-08 10:32:38
合計ジャッジ時間 2,471 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,528 KB
testcase_01 AC 11 ms
6,528 KB
testcase_02 AC 12 ms
6,400 KB
testcase_03 AC 12 ms
6,528 KB
testcase_04 AC 11 ms
6,528 KB
testcase_05 AC 11 ms
6,528 KB
testcase_06 AC 12 ms
6,400 KB
testcase_07 AC 11 ms
6,528 KB
testcase_08 AC 11 ms
6,272 KB
testcase_09 AC 12 ms
6,528 KB
testcase_10 AC 11 ms
6,400 KB
testcase_11 AC 12 ms
6,400 KB
testcase_12 AC 11 ms
6,528 KB
testcase_13 AC 12 ms
6,528 KB
testcase_14 AC 12 ms
6,528 KB
testcase_15 AC 25 ms
7,912 KB
testcase_16 AC 89 ms
13,848 KB
testcase_17 AC 89 ms
13,840 KB
testcase_18 AC 87 ms
14,096 KB
testcase_19 AC 88 ms
13,968 KB
testcase_20 AC 90 ms
14,224 KB
testcase_21 AC 88 ms
14,100 KB
testcase_22 AC 87 ms
13,968 KB
testcase_23 AC 58 ms
11,372 KB
testcase_24 AC 87 ms
13,840 KB
testcase_25 AC 11 ms
6,400 KB
testcase_26 AC 11 ms
6,400 KB
testcase_27 AC 44 ms
11,428 KB
testcase_28 AC 41 ms
11,424 KB
testcase_29 AC 49 ms
12,692 KB
testcase_30 AC 50 ms
12,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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
0