Submission #762788

#TimeUsernameProblemLanguageResultExecution timeMemory
762788MSK17Stove (JOI18_stove)C++14
100 / 100
37 ms2036 KiB
#include <bits/stdc++.h> int main(){ int n,k; std::cin>>n>>k; std::vector<int> t(n), diff(n-1); for(int i{}; i < n; ++i) std::cin>>t[i]; std::sort(t.begin(), t.end()); for(int i{}; i < n-1; ++i) diff[i]=t[i+1]-t[i]-1; std::sort(diff.begin(), diff.end()); long long ans{n}; for(int i{}; i < n-k; ++i) ans+=diff[i]; std::cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...