Submission #849561

#TimeUsernameProblemLanguageResultExecution timeMemory
849561Bach21Stove (JOI18_stove)C++14
20 / 100
2 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n,k; vector<int> v; int mn,mx; signed main() { cin >> n >> k; int prev=0; for (int i=0;i<n;i++) { int x; cin >> x; if (i==0) mn=x; if (i==n-1) mx=x+1; v.push_back(x-prev-1); prev=x; } sort(v.begin(),v.end(),greater<int>()); int res=mx-mn; for (int i=0;i<k-1;i++) { res-=v[i]; } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...