Submission #1151994

#TimeUsernameProblemLanguageResultExecution timeMemory
1151994mehraliiStove (JOI18_stove)C++20
100 / 100
12 ms1864 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define MAXN 200010
#define LOG 17

const int INF = 1e18;


void solve(){
	int n, k; cin >> n >> k;
	vector<int> a(n); for(int&el:a) cin >> el;
	vector<int> b(n-1); for(int i = 1; i < n; i++) b[i-1] = a[i]-a[i-1]-1;
	int total = n;
	sort(b.begin(), b.end());
	for(int i = 0; i < n-k; i++) total+=b[i];
	cout << total;
}


signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1; //cin >> t;
    while(t--) solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...