제출 #413819

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

using namespace std;

int n, k;
vector<int> have;
int a[101010];
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++)cin >> a[i];
    for (int i = 1; i < n; i++)
        have.push_back(a[i + 1] - a[i] - 1);
    sort(have.begin(), have.end(), greater<int>());
    int ans = a[n] - a[1] + 1;
    k--;
    for (auto i : have) {
        if (--k < 0)break;
        ans -= i;
    }
    cout << ans;
}
/**
10 5
1
2
5
6
8
11
13
15
16
20

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