Submission #466057

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