제출 #715336

#제출 시각아이디문제언어결과실행 시간메모리
715336aykhnStove (JOI18_stove)C++14
100 / 100
60 ms2340 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n, 0);

    for (int i = 0; i < n; i++) cin >> v[i];

    sort(all(v));

    vector<int> a;

    for (int i = 1; i < n; i++)
    {
        a.pb(v[i] - v[i - 1]);
    }

    sort(all(a));

    int x = n - k;

    int res = 0;

    for (int i = 0; i < x; i++)
    {
        res += a[i];
    }

    cout << res + k << endl;
}

///1 3 6 10
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...