Submission #159978

#TimeUsernameProblemLanguageResultExecution timeMemory
159978combi1k1Stove (JOI18_stove)C++14
100 / 100
32 ms1316 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n, k; int t[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; --k; priority_queue<int> pq; for(int i = 1 ; i <= n ; ++i) { cin >> t[i]; if (i > 1) pq.push(t[i] - t[i - 1] - 1); } int ans = t[n] - t[1] + 1; for(; k && pq.size() ; --k, pq.pop()) ans -= pq.top(); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...