結果

問題 No.615 集合に分けよう
ユーザー aim_cpoaim_cpo
提出日時 2017-12-15 18:38:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,040 bytes
コンパイル時間 2,787 ms
コンパイル使用メモリ 174,072 KB
実行使用メモリ 4,796 KB
最終ジャッジ日時 2023-08-21 06:44:15
合計ジャッジ時間 3,235 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 21 ms
4,796 KB
testcase_17 AC 18 ms
4,496 KB
testcase_18 AC 18 ms
4,440 KB
testcase_19 AC 18 ms
4,540 KB
testcase_20 AC 19 ms
4,540 KB
testcase_21 AC 18 ms
4,532 KB
testcase_22 AC 21 ms
4,700 KB
testcase_23 AC 15 ms
4,500 KB
testcase_24 AC 18 ms
4,408 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 8 ms
4,476 KB
testcase_28 AC 8 ms
4,484 KB
testcase_29 AC 12 ms
4,424 KB
testcase_30 AC 13 ms
4,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define show(x) cout<<#x<<"="<<x<<"\n"
using namespace std;

int n,m;
string s;
ll a[50001];
ll b[50001];

int main(){
 ios::sync_with_stdio(false);
 cin.tie(0);
 cout.precision(10);
 cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in", "r", stdin); 
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
 cin>>n>>m;
 for(int i=0;i<n;i++){
  cin>>a[i];
 }
 sort(a,a+n);
 vector<pair<ll,int> > v;
 for(int i=1;i<n;i++){
  v.push_back(make_pair(a[i]-a[i-1],i));
 }
 sort(v.begin(),v.end());
 reverse(v.begin(),v.end());
 for(int i=0;i<m-1;i++){
  b[i]=v[i].se;
 }
 sort(b,b+m-1);
 ll ans=0;
 int pre=0;
 for(int i=0;i<m-1;i++){
  ans+=abs(a[pre]-a[b[i]-1]);
  pre=b[i];
 }
 ans+=abs(a[pre]-a[n-1]);
 cout<<ans<<"\n";
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
 return 0;
}
0