Submission #699571

#TimeUsernameProblemLanguageResultExecution timeMemory
699571khshgStove (JOI18_stove)C++14
100 / 100
53 ms2044 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n); vector<int> b(n - 1); for(int i = 0; i < n; ++i) { cin >> a[i]; if(i) { b[i - 1] = a[i] - a[i - 1] - 1; } } sort(rbegin(b), rend(b)); int ans = a[n - 1] - a[0] + 1; for(int i = 0; i < k - 1; ++i) { ans -= b[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...