Submission #260061

#TimeUsernameProblemLanguageResultExecution timeMemory
260061Bill_00Stove (JOI18_stove)C++14
100 / 100
84 ms2168 KiB
#include <bits/stdc++.h> using namespace std; int a[1000001],b[100001]; int main(){ int n,k; cin >> n >> k; for(int i=1;i<=n;i++){ cin >> a[i]; if(i>1) b[i]=a[i]-a[i-1]; } int niit=a[n]-a[1]; if(k==1){ cout << niit+1; return 0; } int sum=0; sort(b+2,b+n+1); for(int i=n;i>=n-k+2;i--){ sum+=b[i]; } cout << niit-sum+k; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...