#include<bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define fi first
#define se second
#define task "stove"
using namespace std;
const int N=1e5+5;
const ll oo=1e18;
const int base=311;
int n,k;
int a[N];
int ans;
vector<int>vec;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;
fo(i,1,n)cin>>a[i];
ans=a[n]+2-a[1];
fo(i,1,n-1)
vec.emplace_back(a[i+1]-a[i]);
sort(vec.begin(),vec.end());
fod(i,vec.size()-1, 0)
{
if(k==1)break;
ans-=vec[i];
k--;
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |