Submission #1017994

#TimeUsernameProblemLanguageResultExecution timeMemory
1017994eldorbek_008Stove (JOI18_stove)C++17
100 / 100
52 ms6832 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n, k; cin >> n >> k; vector<int> t(n); for (int i = 0; i < n; i++) { cin >> t[i]; } int res = t[n - 1] - t[0] + 1; multiset<int> d; for (int i = 1; i < n; i++) { d.insert(t[i] - t[i - 1] - 1); } int i = 0; auto j = d.end(); while (i < k - 1) { res -= *(--j); i += 1; } cout << res << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...