結果
問題 | No.615 集合に分けよう |
ユーザー |
|
提出日時 | 2020-10-14 20:08:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 507 bytes |
コンパイル時間 | 2,105 ms |
コンパイル使用メモリ | 205,176 KB |
最終ジャッジ日時 | 2025-01-15 07:17:16 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long int ll;int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int n,k; cin >> n >> k;vector<ll> x(n);for(int i=0;i<n;i++){cin >> x[i];}sort(x.begin(), x.end());vector<ll> v;ll res=0;for(int i=1;i<n;i++){v.push_back(x[i]-x[i-1]);res+=x[i]-x[i-1];}sort(v.rbegin(), v.rend());for(int i=0;i<k-1;i++){res-=v[i];}cout << res << endl;}