# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978245 | 2024-05-09T04:39:24 Z | PkiraX | Stove (JOI18_stove) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5+5; ll n,k; ll val; ll x[N]; priority_queue <ll> pq; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for(int i=1;i<=n;i++) cin >> x[i]; sort(x+1,x+1+n); for(int i=1;i<n;i++) 3{ pq.push(x[i+1] - (x[i]+1)); } val = (x[n] - x[1]) + 1; for(int i=1;i<=k-1;i++){ val -= pq.top(); pq.pop(); } cout << val; }