結果
問題 | No.615 集合に分けよう |
ユーザー |
![]() |
提出日時 | 2017-12-16 10:33:46 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 632 bytes |
コンパイル時間 | 669 ms |
コンパイル使用メモリ | 85,628 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 19:12:20 |
合計ジャッジ時間 | 2,395 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
#include <iostream>#include <iomanip>#include <cstring>#include <algorithm>#include <math.h>#include <queue>#include <functional>#include <map>#include <vector>#include <string>using namespace std;typedef long long ll;const ll MOD = 1000000007;int n, k;ll a[100005],b[100005];ll ans;int main(void){cin >> n >> k;ans = 0;for (int i = 0; i < n; i++) cin >> a[i];sort(a, a + n);for (int i = 0; i < n - 1; i++){b[i] = a[i + 1] - a[i];ans += b[i];}sort(b, b + n - 1);for (int i = n - 2; i >= n - k; i--){ans -= b[i];}cout << ans << endl;}