Submission #133369

#TimeUsernameProblemLanguageResultExecution timeMemory
133369mlyean00Stove (JOI18_stove)C++14
100 / 100
103 ms2420 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> t(n); for (int i = 0; i < n; ++i) { cin >> t[i]; } vector<int> v; int p = t[0] + 1; for (int i = 1; i < n; ++i) { if (t[i] != p) v.push_back(t[i] - p); p = t[i] + 1; } sort(v.rbegin(), v.rend()); int m = min((int) v.size(), k - 1); int ans = t[n - 1] + 1 - t[0]; for (int i = 0; i < m; ++i) { ans -= v[i]; } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...