제출 #967615

#제출 시각아이디문제언어결과실행 시간메모리
967615njoopStove (JOI18_stove)C++14
100 / 100
23 ms2340 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...