Submission #704218

#TimeUsernameProblemLanguageResultExecution timeMemory
704218alanlStove (JOI18_stove)C++14
100 / 100
22 ms3156 KiB
#include <bits/stdc++.h>
#include <queue>
#define pb push_back
#define F first
#define S second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
	for(const auto &a:p)
		os << a << " ";
	os << "\n";
	return os;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	cin>>n>>k;
	vector<ll> te(n);
	rep(i,0,n) cin>>te[i];
	ll ans=n;
	priority_queue<ll, vector<ll>, greater<ll>> pq;
	rep(i,1,n){
		pq.push(te[i]-te[i-1]);
	}
	while(n>k){
		ans+=pq.top()-1;
		pq.pop();
		n--;
	}
	cout<<ans<<NL;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...