Submission #919441

#TimeUsernameProblemLanguageResultExecution timeMemory
919441KeysStove (JOI18_stove)C++14
100 / 100
21 ms3368 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() signed main(){ ios::sync_with_stdio(0);cin.tie(0); int n,k;cin>>n>>k;vector<int>a(n);for(auto&i:a)cin>>i; sort(all(a)); vector<int>d;for(int i=1;i<n;i++)d.push_back(max(0ll,a[i]-a[i-1]-1)); sort(all(d)); reverse(all(d)); int sub=0;for(int i=0;i<min(k-1,n-1);i++)sub+=d[i]; cout<<a.back()-a[0]-sub+1<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...