Submission #96317

#TimeUsernameProblemLanguageResultExecution timeMemory
96317hugo_pmStove (JOI18_stove)C++14
100 / 100
23 ms2824 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= b; --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second
#define BIG 1000000000000000000

typedef long long ll;
typedef long double ld;

void cpr(string s, vector<int> v)
{ int i = 0; for (char c : s) { if (c == '$') cout << v[i++]; else cout << c; } cout << '\n'; }

void cpr(string s) { cpr(s, {}); }

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> d(n-1);
	form(i, n) {
		cin >> a[i];
		if (i) d[i-1] = a[i] - a[i-1];
	}
	sort(d.begin(), d.end());
	int tot = a.back() + 1 - a.front();
	form(i, k-1) {
		tot -= d.back()-1;
		d.pop_back();
	}
	cout << tot << "\n";

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...