Submission #718692

#TimeUsernameProblemLanguageResultExecution timeMemory
718692AndrijaMStove (JOI18_stove)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(true); long long n; long long k; cin>>n>>k; long long x[n+1]; long long mx=0; long long mi=1e18; for(long long i=1;i<=n;i++) { cin>>x[i]; mx=max(mx,x[i]); mi=min(mi,x[i]); } long long a[n+1]; memset(a,0,sizeof a); for(long long i=1;i<n;i++) { a[i]=x[i+1]-x[i]-1; } sort(a,a+n); reverse(a,a+n); long long ans=mx-mi+1; for(long long i=1;i<k;i++) { ans-=a[i]; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...