Submission #466066

#TimeUsernameProblemLanguageResultExecution timeMemory
466066fuad27Stove (JOI18_stove)C++17
100 / 100
58 ms2796 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main () { int n, k; cin >> n >> k; int t[n], d[n]; for(int i = 0;i<n;i++) { cin >> t[i]; } for(int i = 0;i<n-1;i++)d[i] = t[i+1] - t[i] - 1; int ans =t[n-1] - t[0] + 1; sort(d, d+n-1, greater<int>()); for(int i = 1;i<k;i++)ans-=d[i-1]; cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...