Submission #1005863

#TimeUsernameProblemLanguageResultExecution timeMemory
1005863OtalpStove (JOI18_stove)C++14
100 / 100
59 ms6064 KiB
#include<bits/stdc++.h> using namespace std; void solve(){ int n, k; cin>>n>>k; multiset<int> d; k = min(k-1, n-1); int mn=1e9, mx=0; int ls = -1; for(int i=1; i<=n; i++){ int x; cin>>x; mn = min(mn, x); mx = max(mx, x); if(ls != -1) d.insert(x - ls-1); ls = x; } int ans = mx - mn + 1; while(k--){ auto it = *d.rbegin(); ans -= it; d.erase(d.find(it)); //cout<<it<<'\n'; } cout<<ans; } int main(){ solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...