Submission #530673

#TimeUsernameProblemLanguageResultExecution timeMemory
530673GurbanStove (JOI18_stove)C++17
100 / 100
48 ms2740 KiB
#include <iostream> #include <algorithm> #define ll long long int using namespace std; ll n,k,ans,a[100001]; vector<int>v; int main(){ cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; if(k>=n) cout<<n<<endl; else{ for(int i=2;i<=n;i++){ v.push_back(a[i] - a[i-1] - 1); } sort(v.begin(),v.end()); for(int i=0;i<n-k;i++) ans+=v[i]; cout<<ans+n<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...