Submission #421940

#TimeUsernameProblemLanguageResultExecution timeMemory
421940GabpStove (JOI18_stove)C++17
100 / 100
61 ms2272 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n,k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; priority_queue<int> pq; for (int i = 0; i < n - 1; i++) { pq.push(max(0, a[i + 1] - 1 - a[i])); } int total = a[n - 1] - a[0] + 1; while (!pq.empty() && k > 1) { auto i = pq.top(); pq.pop(); total -= i; k--; } cout << total; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...