Submission #818747

#TimeUsernameProblemLanguageResultExecution timeMemory
818747vjudge1Stove (JOI18_stove)C++17
100 / 100
19 ms2260 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAXN = 1e5 + 5; ll n, k; ll a [MAXN]; priority_queue <ll, vector <ll> , greater <ll> > pq; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; ll ans = n; for(ll i = 1; i <= n; i++){ cin >> a[i]; } for(ll i = 1; i <= n-1; i++){ pq.push(a[i+1] - (a[i]+1)); } ll sambung = n - k; while(sambung--){ ans += pq.top(); pq.pop(); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...