제출 #1279907

#제출 시각아이디문제언어결과실행 시간메모리
1279907dhuyyyyStove (JOI18_stove)C++20
100 / 100
19 ms2332 KiB
#include<bits/stdc++.h> #define fi first #define se second #define int long long using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 2e5+5; int n, k, res = 0; int a[N]; priority_queue<int> pq; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); cin >> n >> k; for (int i = 1; i <= n; i++){ cin >> a[i]; } sort(a+1,a+1+n); for (int i = 2; i <= n; i++) pq.push(a[i] - a[i-1]); k--; res -= k; while (k--){ res += pq.top(); pq.pop(); } cout << (a[n] + 1 - a[1]) - res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...