結果

問題 No.615 集合に分けよう
ユーザー monnu
提出日時 2020-10-04 18:11:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 172,392 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 17:36:40
合計ジャッジ時間 3,832 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007

/*
srand((unsigned int)time(NULL));
for(int i=0;i<10;i++){
  cout<<rand()%6+1<<" ";
}
*/
/*
clock_t start,end;
start=clock();
end=clock();
double t=(double)(end-start)/CLOCKS_PER_SEC;
t<2.9;
*/

int main(){
  int N,K;
  cin>>N>>K;
  vector<ll> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  vector<ll> diff(N-1,0);
  for(int i=0;i<N-1;i++){
    diff[i]=a[i+1]-a[i];
  }
  sort(diff.begin(),diff.end());
  ll ans=0;
  for(int i=0;i<N-K;i++){
    ans+=diff[i];
  }
  cout<<ans<<endl;
}
0