結果
| 問題 | No.615 集合に分けよう | 
| コンテスト | |
| ユーザー |  merom686 | 
| 提出日時 | 2017-12-15 00:10:42 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 743 bytes | 
| コンパイル時間 | 957 ms | 
| コンパイル使用メモリ | 79,200 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-14 13:45:31 | 
| 合計ジャッジ時間 | 1,922 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 23 WA * 3 | 
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (k == 1) {
        cout << a[n - 1] - a[0] << endl;
        quick_exit(0);
    }
    sort(a.begin(), a.end());
    vector<int64_t> b(n - 1);
    for (int i = 0; i < n - 1; i++) {
        b[i] = a[i + 1] - a[i];
    }
    sort(b.begin(), b.end());
    int64_t r = 0;
    for (int i = 0; i < k - 1; i++) {
        r += b[n - 2 - i];
    }
    cout << a[n - 1] - a[0] - r << endl;
    return 0;
}
            
            
            
        