Submission #237264

#TimeUsernameProblemLanguageResultExecution timeMemory
237264michaoStove (JOI18_stove)C++14
0 / 100
5 ms384 KiB
#include <bits/stdc++.h> #define ll long long int #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=1e5+5; const int inf=1e9+9; int tab[MAX]; ll ans=0; vi diff; int32_t main() { BOOST; int n,k; cin>>n>>k; int mini=inf,maxi=-inf; for (int i=1;i<=n;i++)cin>>tab[i],mini=min(mini,tab[i]),maxi=max(maxi,tab[i]); ans=maxi-mini+1; for (int i=2;i<=n;i++)diff.pb(tab[i]-tab[i-1]-1); sort(diff.begin(),diff.end(),greater<int>()); k=(n-k-1); for (int i=0;i<k;i++)ans-=diff[i]; cout<<ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...