Submission #706716

#TimeUsernameProblemLanguageResultExecution timeMemory
706716esomerStove (JOI18_stove)C++17
100 / 100
26 ms1680 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int ll; const int MOD = 1e9 + 7; void solve(){ int n, k; cin >> n >> k; vector<int> v(n - 1); int lst = -1; for(int i = 0; i < n; i++){ int x; cin >> x; if(i == 0){lst = x; continue;} v[i - 1] = x - lst - 1; lst = x; } sort(v.begin(), v.end()); int curr = n; ll ans = n; for(int i = 0; i < n - 1 && curr > k; i++){ ans += v[i]; curr--; } cout << ans << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); //~ int tt; cin >> tt; int tt = 1; for(int t = 1; t <= tt; t++){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...