Submission #72795

#TimeUsernameProblemLanguageResultExecution timeMemory
72795DiuvenStove (JOI18_stove)C++14
100 / 100
43 ms10640 KiB
#include <bits/stdc++.h> using namespace std; int n,k,T[100010],ans; vector<int> V; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>k; for(int i=1; i<=n; i++) cin>>T[i]; sort(T+1, T+n+1); for(int i=1; i<=n; i++) if(T[i]!=T[i-1]) ans++; for(int i=1; i<n; i++) if(T[i+1]>T[i]+1) V.push_back(T[i+1]-T[i]-1); sort(V.begin(), V.end()); for(int i=0; i<(int)V.size()-(k-1); i++) ans+=V[i]; cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...