Submission #260729

#TimeUsernameProblemLanguageResultExecution timeMemory
260729arborStove (JOI18_stove)C++14
100 / 100
26 ms2176 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<int, int>; const int MN = 1e5 + 5; int main() { ios_base::sync_with_stdio(0), cin.tie(0); 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; int ans = a[N - 1] - a[0] + 1; sort(d.rbegin(), d.rend()); for (int i = 0; i < K - 1; i++) 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...