結果

問題 No.615 集合に分けよう
ユーザー ohreitetsu
提出日時 2018-09-06 21:38:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 445 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 74,540 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 04:52:04
合計ジャッジ時間 2,615 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 24 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,K;
	cin>>N>>K;
	vector<LL> A(N),B(N-1);
	int i;
	for (i=0;i<N;i++){
		cin>>A[i];
	}
	if (N==1){
		cout<<A[0];
		return 0;
	}
	sort(A.begin(),A.end());
	for (i=1;i<N;i++){
		B[i-1]=A[i]-A[i-1];
	}
	sort(B.begin(),B.end());
	LL ans=0;
	for (i=0;i<N-K;i++){
		ans+=B[i];
	}
	cout<<ans<<endl;
	return 0;
}
0