Submission #223721

#TimeUsernameProblemLanguageResultExecution timeMemory
223721bharat2002Stove (JOI18_stove)C++14
100 / 100
29 ms3064 KiB
/*input
3 2
1
3
6
*/
#include<bits/stdc++.h>
using namespace std;
const int N=1e5 + 100;
const int mod=1e9 + 7;
#define int long long
const int inf=1e18;
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
#define FOR(i, n) for(int i=1;i<=n;i++)
#define TRACE(x) cerr << #x << " = " << x << endl 
//Trace prints the name of the variable and the value.
int ans, arr[N];vector<int> vals;
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n, k;cin>>n>>k;

	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		if(i>1) vals.push_back(arr[i]-arr[i-1]);
	}
	sort(vals.begin(), vals.end());
	ans=n;
	for(int i=0;i<n-k;i++)
	{
		ans+=vals[i]-1;
	}
	cout<<ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...