Submission #86598

#TimeUsernameProblemLanguageResultExecution timeMemory
86598KCSCStove (JOI18_stove)C++14
100 / 100
82 ms10408 KiB
#include <bits/stdc++.h> using namespace std; const int DIM = 100005; int lst[DIM], arr[DIM]; int main(void) { #ifdef HOME freopen("stove.in", "r", stdin); freopen("stove.out", "w", stdout); #endif int n, k; cin >> n >> k; --k; for (int i = 1; i <= n; ++i) { cin >> arr[i]; if (i > 1) { lst[i - 1] = arr[i] - arr[i - 1] - 1; } } sort(lst + 1, lst + n, greater<int>()); int ans = arr[n] - arr[1] + 1; for (int i = 1; i <= k; ++i) { ans -= lst[i]; } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...