結果
| 問題 | No.615 集合に分けよう | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-15 11:41:05 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 32 ms / 2,000 ms | 
| コード長 | 458 bytes | 
| コンパイル時間 | 476 ms | 
| コンパイル使用メモリ | 59,128 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-14 15:56:03 | 
| 合計ジャッジ時間 | 1,740 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 26 | 
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long int ll;
const int S = 50000;
ll a[S],n,k,dif[S];
int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n - 1; i++)dif[i] = a[i + 1] - a[i];
	sort(dif, dif + n - 1);
	ll d_tot = 0;
	for (int i = 0; i < k - 1; i++)d_tot += dif[n-2-i];
	cout << a[n - 1] - a[0] - d_tot << endl;
	return 0;
}
            
            
            
        