Submission #503588

#TimeUsernameProblemLanguageResultExecution timeMemory
503588lucriStove (JOI18_stove)C++17
100 / 100
56 ms700 KiB
#include <iostream> #include <algorithm> using namespace std; int n,k,t[100010],ans; int main() { cin>>n>>k; for(int i=1;i<=n;++i) cin>>t[i]; sort(t+1,t+n+1); ans=t[n]+1-t[1]; for(int i=1;i<n;++i) t[i]=t[i+1]-t[i]-1; sort(t+1,t+n); for(int i=n-1;i>0&&i>=n-k+1;--i) ans-=t[i]; cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...