Submission #1037338

#TimeUsernameProblemLanguageResultExecution timeMemory
1037338ivazivaStove (JOI18_stove)C++14
100 / 100
31 ms3340 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 100001 long long n,k; long long a[MAXN]; vector<long long> raz; int main() { cin>>n>>k; for (long long i=1;i<=n;i++) cin>>a[i]; for (long long i=2;i<=n;i++) raz.push_back(a[i]-a[i-1]-1); sort(raz.begin(),raz.end()); long long ans=n; for (long long i=0;i<n-k;i++) ans+=raz[i]; cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...