Submission #939434

#TimeUsernameProblemLanguageResultExecution timeMemory
939434ifateenStove (JOI18_stove)C++14
100 / 100
43 ms2284 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int arr[MAXN]; vector<int> diff; int main() { int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> arr[i], diff.push_back(arr[i] - (arr[i - 1] + 1)); diff.erase(diff.begin()); sort(rbegin(diff), rend(diff)); --k; int ans = arr[n] + 1 - arr[1]; for (int i = 0; i < k; i++) ans -= diff[i]; cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...