Submission #967617

#TimeUsernameProblemLanguageResultExecution timeMemory
967617njoopStove (JOI18_stove)C++17
100 / 100
20 ms1504 KiB
#include <bits/stdc++.h> using namespace std; int n, k, arr[100010], ans; priority_queue<int> pq; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k; k--; for(int i=0; i<n; i++) { cin >> arr[i]; } sort(arr, arr+n); for(int i=1; i<n; i++) { pq.push(arr[i]-arr[i-1]-1); } ans = arr[n-1] - arr[0]+1; while(k--) { ans -= pq.top(); pq.pop(); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...