Submission #48473

#TimeUsernameProblemLanguageResultExecution timeMemory
48473kyleliuStove (JOI18_stove)C++14
100 / 100
26 ms11504 KiB
#include <bits/stdc++.h> // PLEASE

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pp;
#define MAXN 300005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N, K;
ll V[MAXN];
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	vector <ll> difs;
	cin >> N >> K;
	ll ans = (ll)K;
	for(int i=0; i<N; i++) cin >> V[i];
	for(int i=0; i+1<N; i++) {
		difs.PB(V[i+1]-V[i]);
		ans += V[i+1] - V[i];
	}
	sort(difs.begin(), difs.end());
	reverse(difs.begin(), difs.end());
	for(int i=0; i<K-1; i++) ans -= difs[i];
	cout << ans << endl;
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...