Submission #995935

#TimeUsernameProblemLanguageResultExecution timeMemory
995935yanbStove (JOI18_stove)C++14
100 / 100
14 ms2808 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int> a(n), d(n - 1); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { d[i] = a[i + 1] - a[i] - 1; } sort(d.begin(), d.end()); int ans = n; for (int i = 0; i < n - k; i++) { ans += d[i]; } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...