Submission #921895

#TimeUsernameProblemLanguageResultExecution timeMemory
921895beanStove (JOI18_stove)C++17
100 / 100
20 ms2140 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, k; cin >> n >> k; vector<int> a(n); for (int &x : a) cin >> x; int ans = a[n - 1] - a[0] + 1; vector<int> b(n - 1); for (int i = 0; i < n - 1; i++) { b[i] = a[i + 1] - a[i] - 1; } sort(b.begin(), b.end(), greater<>()); for (int i = 0; i < k - 1; i++) { ans -= b[i]; } cout << ans; } int main() { cin.tie(0)->sync_with_stdio(0); int tt = 1; // cin >> tt; while (tt--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...