#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll p[100001],a,b,ans,c,i;
vector<ll>v;
int main(){
cin>>a>>b;
for(i=1;i<=a;i++){
cin>>p[i];
if(i>1){
v.pb(p[i]-p[i-1]-1);
}
}
ans=p[a];
if(a<=b){
cout<<a<<endl;
v.clear();
}
else{
b--;
sort(v.begin(),v.end());
c=a-2;
for(i=1;i<=b;i++){
ans-=v[c];
c--;
}
cout<<ans<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |