Submission #591957

#TimeUsernameProblemLanguageResultExecution timeMemory
591957MahtimursuStove (JOI18_stove)C++17
100 / 100
53 ms2280 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; int ans = v[n - 1] + 1 - v[0]; vector<int> improv; for (int i = 1; i < n; ++i) { improv.push_back(v[i] - v[i - 1] - 1); } sort(improv.rbegin(), improv.rend()); for (int i = 1; i < k; ++i) ans -= improv[i - 1]; cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...