Submission #625246

#TimeUsernameProblemLanguageResultExecution timeMemory
625246Genius3435Stove (JOI18_stove)C++17
100 / 100
63 ms2072 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a (n); for (int &x : a) cin >> x; vector<int> diff (n-1); for (int i = 0; i < n-1; ++i) { if (a[i+1] == a[i]+1) continue; diff[i] = a[i+1] - a[i] - 1; } sort(diff.begin(), diff.end()); int ans = 0; for (int i = 0; i < n-k; ++i) { ans += diff[i]; } cout << ans+n << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...