Submission #586716

#TimeUsernameProblemLanguageResultExecution timeMemory
586716VanillaStove (JOI18_stove)C++17
100 / 100
42 ms1876 KiB
#include <bits/stdc++.h> using namespace std;typedef long long p;int main(){int n,k;cin>>n>>k;vector<p>a(n);vector<p>x(n-1);for(int i=0;i<n;i++){cin>>a[i];if(i!= 0)x[i-1]=a[i]-a[i-1]-1;}p rs=a[n-1]-a[0]+1;sort(x.begin(),x.end(),greater<p>());for(int i=0;i<k-1;i++){rs-=x[i];}cout<<rs<<"\n";return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...