Submission #322086

#TimeUsernameProblemLanguageResultExecution timeMemory
322086kwongwengStove (JOI18_stove)C++14
100 / 100
52 ms2156 KiB
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i < b; i++) int main(){ int n, k; cin >> n >> k; vector<int> t(n); FOR(i, 0, n) cin >> t[i]; int ans = t[n-1] + 1 - t[0]; vector<int> d(n-1); FOR(i, 0, n-1){ d[i] = t[i+1] - t[i] - 1; } sort(d.begin(), d.end()); FOR(i, n-k, n-1){ ans -= d[i]; } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...