Submission #409972

#TimeUsernameProblemLanguageResultExecution timeMemory
409972jenkinsserStove (JOI18_stove)C++17
100 / 100
27 ms2212 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define st first #define nd second #define pii pair<int,int> #define piii pair<int,pii> #define sp " " #define nl "\n" #define all(x) x.begin(),x.end() #define fastio() ios_base::sync_with_stdio(0);cin.tie(0); #define ll long long using namespace std; const int N = 1e5+5; const int INF = 1e9+5; const int mod = 1e9+7; int n,k,a[N],ans; signed main(){ fastio() cin >> n >> k; vector<int> v; for(int i=1;i<=n;i++){ cin >> a[i]; if(i>1){ ans+=a[i]-a[i-1]; v.pb(a[i]-a[i-1]); } } sort(v.rbegin(),v.rend()); for(int i=0;i<k-1;i++){ ans-=v[i]; } cout << ans+k << nl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...