結果

問題 No.615 集合に分けよう
ユーザー silopysilopy
提出日時 2019-07-06 01:58:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 371 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 69,408 KB
実行使用メモリ 19,308 KB
最終ジャッジ日時 2023-10-23 21:10:59
合計ジャッジ時間 2,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
19,308 KB
testcase_01 AC 6 ms
19,308 KB
testcase_02 AC 6 ms
19,308 KB
testcase_03 AC 6 ms
19,308 KB
testcase_04 AC 7 ms
19,308 KB
testcase_05 AC 6 ms
19,308 KB
testcase_06 AC 5 ms
19,308 KB
testcase_07 AC 6 ms
19,308 KB
testcase_08 AC 6 ms
19,308 KB
testcase_09 AC 8 ms
19,308 KB
testcase_10 AC 6 ms
19,308 KB
testcase_11 AC 6 ms
19,308 KB
testcase_12 AC 7 ms
19,308 KB
testcase_13 AC 7 ms
19,308 KB
testcase_14 AC 6 ms
19,308 KB
testcase_15 AC 13 ms
19,308 KB
testcase_16 AC 38 ms
19,308 KB
testcase_17 AC 38 ms
19,308 KB
testcase_18 AC 37 ms
19,308 KB
testcase_19 AC 37 ms
19,308 KB
testcase_20 AC 37 ms
19,308 KB
testcase_21 AC 37 ms
19,308 KB
testcase_22 AC 37 ms
19,308 KB
testcase_23 AC 18 ms
19,308 KB
testcase_24 AC 33 ms
19,308 KB
testcase_25 AC 6 ms
19,308 KB
testcase_26 AC 6 ms
19,308 KB
testcase_27 AC 15 ms
19,308 KB
testcase_28 AC 14 ms
19,308 KB
testcase_29 AC 31 ms
19,308 KB
testcase_30 AC 32 ms
19,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
using lint=int64_t;

int main()
{
	int N,K;
	lint a[1000010]={};

	cin >> N >> K;
	for(int i=0;i<N;i++)
		cin >> a[i];

	sort(a,a+N);
	lint sub[1000010]={};
	for(int i=0;i<N-1;i++)
		sub[i]=a[i+1]-a[i];
	sort(sub,sub+N-1);

	lint ans=0;
	for(int i=0;i<N-K;i++)
		ans+=sub[i];
	cout << ans << endl;
	return 0;
}
0