Submission #196894

#TimeUsernameProblemLanguageResultExecution timeMemory
196894JuneyStove (JOI18_stove)C++14
100 / 100
26 ms2168 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5 + 5;

int N, K;
int A[MAXN], T[MAXN], ans;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	for(int i=1; i<=N; i++) cin >> T[i];
	for(int i=1; i<N; i++) A[i] = T[i+1] - T[i]-1;
	sort(A+1, A+N, greater<int>());
	ans = T[N]+1 - T[1];
	for(int i=1; i<K; i++) ans -= A[i];
	cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...