Submission #821391

#TimeUsernameProblemLanguageResultExecution timeMemory
821391TwinHterStove (JOI18_stove)C++14
100 / 100
17 ms2848 KiB
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

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

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define popb pop_back
#define pf push_front
#define popf pop_front

string alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
const ll pd = 1e9+7;//998244353;
ll oo = 1e18 + 1, tc;
const ll MX = 240010;
void solve() {
	int n, k; cin >> n >> k;
	ll a[n+10], time = 0, b[n+10];
	for(int i=1; i<=n; i++) cin >> a[i];
	for(int i=2; i<=n; i++) b[i-1] = max(a[i]-a[i-1]-1, (ll)0);
	
	sort(b+1, b+n, greater<ll>());
	time = a[n]-a[1]+1;
	for(int i=1; i<=min(n-1, k-1); i++) time -= b[i];
	cout << time << endl;
}
int main (){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("cf.inp", "r", stdin); freopen("cf.out", "w", stdout);
	//cin >> tc; while(tc--)
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...