#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ios_base::sync_with_stdio();cin.tie(nullptr);
ll n, k;
cin>>n>>k;
vector<ll> a;
for(int i = 0; i < n; i++){
ll aa;
cin>>aa;
a.push_back(aa);
}
vector<ll> s;
for(int i = 0; i < n-1; i++){
s.push_back(a[i+1]-a[i]-1);
}
ll all=a[n-1];
if(k>=n)cout<<n;
else{
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
for(int i = 0; i < k-1; i++){
//cout<<s[i]<<endl;
all-=s[i];
}
cout<<all;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |