#include <bits/stdc++.h>
#define len(x) (int)x.size()
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e5 + 5;
vector <int> v;
int n,k,a[N];
ll cnt;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i=1;i<=n;i++){
cin >> a[i];
}
k--;
for (int i=2;i<=n;i++){
v.pb(a[i] - (a[i-1] + 1));
}
sort(v.begin(), v.end(), greater<int>());
for (int i=0;i<k;i++){
cnt+=v[i];
}
cout << a[n] - cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |