Submission #206392

#TimeUsernameProblemLanguageResultExecution timeMemory
206392stefdascaStove (JOI18_stove)C++14
100 / 100
67 ms6904 KiB
#include<bits/stdc++.h> using namespace std; int n, k, x, v[100002], beg[100002]; set<pair<int, int> >s; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; x = n; for(int i = 1; i <= n; ++i) cin >> v[i]; for(int i = 1; i <= n; ++i) { beg[i] = 1; if(i < n) s.insert({v[i+1] - v[i], i+1}); } while(x > k) { pair<int, int> xx = *s.begin(); s.erase(xx); beg[xx.second] = 0; --x; } int cost = 0; int lst = 0; beg[n+1] = 1; for(int i = 1; i <= n+1; ++i) { if(beg[i] == 1) { if(lst != 0) { cost = cost + v[i-1] - lst + 1; lst = v[i]; } else lst = v[i]; } } cout << cost; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...