結果

問題 No.615 集合に分けよう
ユーザー posaune-0xa0
提出日時 2018-06-25 23:04:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 79,344 KB
最終ジャッジ日時 2025-01-06 11:35:49
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;
typedef long long ll;

int main(void)
{
    ll N, K, a, ans;
    cin >> N >> K;
    vector<ll> v, vv;
    for(int i = 0; i < N; i++)
    {
        cin >> a;
        v.push_back(a);
    }

    sort(v.begin(), v.end());

    for(int i = 1; i != v.size(); i++)
    {
        vv.push_back(llabs(v[i]-v[i-1]));
    }

    sort(vv.begin(), vv.end());

    ans = v.back() - v[0];
    for(int i = 0; i < K-1; i++)
    {
        ans -= vv.back();
        vv.pop_back();
    }

    cout << ans << endl;

    return 0;
}
0