Submission #159242

#TimeUsernameProblemLanguageResultExecution timeMemory
159242sochoStove (JOI18_stove)C++14
100 / 100
88 ms2184 KiB
#include "bits/stdc++.h" using namespace std; int main() { int n, k; cin >> n >> k; int arr[n]; for (int i=0; i<n; i++) { cin >> arr[i]; } sort(arr, arr+n); int sm = arr[n-1] + 1 - arr[0]; k--; int df[n-1]; for (int i=0; i<n-1; i++) { df[i] = arr[i+1] - arr[i] - 1; } sort(df, df+n-1, greater<int>()); for (int i=0; i<k; i++) { sm -= df[i]; } cout << sm << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...