Submission #1331961

#TimeUsernameProblemLanguageResultExecution timeMemory
1331961ChinguunStove (JOI18_stove)C++20
100 / 100
14 ms2008 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define meta int tm = (tl + tr) / 2, x = i * 2 + 1, y = x + 1

const int N = 2e5 + 7;
const int TN = 4 * N;
const int oo = 1e18;
const int mod = 1e9 + 7;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

int n, k, a[N], b[N], ans;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i == 1) continue;
		b[i] = a[i] - a[i - 1];
	}
	sort (b + 2, b + n + 1);
	for (int i = 2; i <= n - k + 1; i++) {
		ans += b[i];
	} cout << ans + k;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...