結果

問題 No.615 集合に分けよう
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-07-01 10:44:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 345 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 86,972 KB
実行使用メモリ 86,728 KB
最終ジャッジ日時 2023-09-10 08:26:33
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,328 KB
testcase_01 AC 71 ms
71,424 KB
testcase_02 AC 70 ms
71,332 KB
testcase_03 AC 68 ms
71,236 KB
testcase_04 AC 69 ms
71,256 KB
testcase_05 AC 68 ms
71,232 KB
testcase_06 AC 69 ms
71,328 KB
testcase_07 AC 69 ms
71,452 KB
testcase_08 AC 71 ms
71,104 KB
testcase_09 AC 70 ms
71,404 KB
testcase_10 AC 70 ms
71,056 KB
testcase_11 AC 70 ms
71,144 KB
testcase_12 AC 70 ms
71,308 KB
testcase_13 AC 71 ms
71,056 KB
testcase_14 AC 86 ms
74,988 KB
testcase_15 AC 76 ms
75,896 KB
testcase_16 AC 104 ms
86,728 KB
testcase_17 AC 85 ms
82,576 KB
testcase_18 AC 105 ms
86,392 KB
testcase_19 AC 104 ms
86,284 KB
testcase_20 AC 105 ms
86,112 KB
testcase_21 AC 104 ms
86,336 KB
testcase_22 AC 105 ms
86,536 KB
testcase_23 AC 93 ms
84,488 KB
testcase_24 AC 102 ms
85,732 KB
testcase_25 AC 72 ms
71,240 KB
testcase_26 AC 72 ms
71,236 KB
testcase_27 AC 82 ms
80,852 KB
testcase_28 AC 82 ms
80,808 KB
testcase_29 AC 84 ms
82,484 KB
testcase_30 AC 90 ms
85,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main1(n,k,a):
  if k==1:return max(a)-min(a)
  a.sort()
  ary=[]
  for i,(x,y) in enumerate(zip(a,a[1:])):
    ary.append(y-x)
  ary.sort()
  return max(a)-min(a)-sum(ary[-k+1:])

if __name__=='__main__':
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  #ret0=main0(n,k,a)
  ret1=main1(n,k,a)
  #print(ret0)
  print(ret1)
0