Submission #392529

#TimeUsernameProblemLanguageResultExecution timeMemory
392529lukameladzeStove (JOI18_stove)C++14
100 / 100
56 ms3200 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back using namespace std; const int N=3e5+5; long long a[N],n,k,ans; vector <long long> v; int main() { cin>>n>>k; for (int i=1; i<=n; i++) { cin>>a[i]; } // if (n==k) { //cout<<k<<endl; //return 0; // } for (int i=1; i<n; i++) { v.pb(a[i]-a[i+1]); } sort(v.begin(), v.end()); // reverse(v.begin(),v.end()); for(int i=0; i<min(int(v.size()),int(k-1)); i++) { ans+=v[i]; } ans+=(a[n]+1-a[1])+(k-1); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...