//Mert Akarca <3
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,k,temp,temp1,nk,ans;
vector <int> fark;
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>k;
for(int j = 0; j<n; ++j)
{
cin>>temp;
if(j != 0) fark.push_back(temp-(temp1+1));
temp1 = temp;
}
nk = fark.size();
sort(fark.begin(),fark.end());
/* for(int j = 0; j<nk; ++j)
{
cout<<fark[j]<<" ";
}*/
for(int j = nk-1; k-1 != 0; --j)
{
fark[j] = 0;
--k;
}
for(int j = 0; j<nk; ++j)
{
ans += fark[j];
}
cout<<ans+n;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |