Submission #270516

#TimeUsernameProblemLanguageResultExecution timeMemory
270516REALITYNBStove (JOI18_stove)C++14
100 / 100
99 ms3312 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ int n ; int k ; cin>> n >>k ; vector<int> a(n) ; for(int& x : a) cin>>x ; int ans = 0 ; for(int i=1;i<n;i++) ans+=a[i]-a[i-1]-1 ; vector<int> b ; for(int i=1;i<n;i++){ b.push_back(a[i-1]-a[i]+1) ; } sort(b.begin(),b.end()) ; for(int i=0;i<k-1;i++){ b[i]*=-1 ; ans-=b[i] ; } cout << ans+n ; return 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...