結果

問題 No.615 集合に分けよう
ユーザー NoaSaberNoaSaber
提出日時 2021-03-14 09:37:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 336 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 86,348 KB
最終ジャッジ日時 2024-04-23 18:45:09
合計ジャッジ時間 4,232 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,096 KB
testcase_01 AC 34 ms
51,968 KB
testcase_02 AC 33 ms
52,224 KB
testcase_03 AC 32 ms
52,096 KB
testcase_04 AC 35 ms
51,840 KB
testcase_05 AC 34 ms
52,096 KB
testcase_06 AC 33 ms
52,096 KB
testcase_07 AC 35 ms
52,352 KB
testcase_08 AC 37 ms
52,072 KB
testcase_09 AC 35 ms
51,968 KB
testcase_10 AC 34 ms
52,560 KB
testcase_11 AC 34 ms
52,736 KB
testcase_12 AC 35 ms
52,608 KB
testcase_13 AC 36 ms
52,736 KB
testcase_14 AC 42 ms
59,392 KB
testcase_15 AC 68 ms
76,800 KB
testcase_16 AC 180 ms
86,192 KB
testcase_17 AC 160 ms
86,144 KB
testcase_18 AC 160 ms
86,348 KB
testcase_19 AC 169 ms
86,144 KB
testcase_20 AC 181 ms
85,852 KB
testcase_21 AC 180 ms
85,988 KB
testcase_22 AC 175 ms
86,196 KB
testcase_23 AC 70 ms
82,560 KB
testcase_24 AC 163 ms
85,712 KB
testcase_25 AC 35 ms
51,968 KB
testcase_26 AC 33 ms
52,096 KB
testcase_27 AC 60 ms
80,256 KB
testcase_28 AC 58 ms
80,512 KB
testcase_29 AC 71 ms
86,016 KB
testcase_30 AC 80 ms
85,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[]
for i in range(N-1):
    b.append((a[i+1]-a[i],i))
b.sort(reverse=True)
c=[b[i][1] for i in range(K-1)]
c=set(c)
ans=0
check=set()
for i in range(N):
    check.add(a[i])
    if i in c or i==N-1:
        ans+=max(check)-min(check)
        check=set()
print(ans)
0