Submission #315252

#TimeUsernameProblemLanguageResultExecution timeMemory
315252Jarif_RahmanStove (JOI18_stove)C++17
100 / 100
28 ms2796 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; ll mn = 1e18, mx = -1e18;; vector <ll> v(n); for(ll &x: v){ cin >> x; mn = min(mn, x); mx = max(mx, x); } if(k >= n){ cout << n << "\n"; exit(0); } ll ans = mx - mn + 1; priority_queue<int> pq; for(int i = 0; i < n - 1; i++) pq.push(v[i+1]-v[i]-1); k--; while(k--) ans-= pq.top(), pq.pop(); cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...