이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |