# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964168 | 2024-04-16T11:44:56 Z | mel | Stove (JOI18_stove) | C++14 | 0 ms | 0 KB |
#include <iostream> #include <algorithm> using namespace std; #define int long long int arr[100005]; int dif[100005]; signed main() { int n; cin >> n; int k; cin >> k; for (int i =0; i<n; i++){ cin >> arr[i]; } sort(arr, arr+n); for(int i = 0;i<(n-1);i++){ dif[i] = arr[i+1]-arr[i]; } sort(dif, dif+(n-1)); if (k>=n) { cout << n; } else { int cnt = k; for (int i = 0; i<(n-k); i++) { cnt+= dif[i]; } cout << cnt; } } ~