Submission #1130584

#TimeUsernameProblemLanguageResultExecution timeMemory
1130584lopkusStove (JOI18_stove)C++20
100 / 100
17 ms2244 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> V; for(int i = 2; i <= n; i++) { V.push_back(a[i] - a[i - 1]); } sort(V.begin(), V.end()); if(k >= n) { cout << n; return 0; } if(k == 1) { cout << a[n] + 1 - a[1]; return 0; } int ans = 0; for(int i = 0; i < n - k; i++) { ans += V[i]; } cout << ans + k; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...