Submission #485912

#TimeUsernameProblemLanguageResultExecution timeMemory
485912status_codingStove (JOI18_stove)C++14
100 / 100
41 ms6352 KiB
#include <bits/stdc++.h> using namespace std; int n,k,ans; int v[100005]; multiset<int> s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int i=1;i<=n;i++) cin>>v[i]; ans=v[n]+1-v[1]; k--; for(int i=2;i<=n;i++) s.insert(v[i]-v[i-1]-1); while(k) { k--; auto it = prev(s.end()); ans -= *it; s.erase(it); } cout<<ans<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...