Submission #891841

#TimeUsernameProblemLanguageResultExecution timeMemory
891841hennesseyStove (JOI18_stove)C++17
100 / 100
43 ms3600 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { //your code goes here int n, k; cin >> n >> k; vector <int> arr = {}; for(int i = 0; i < n; i++) { int num; cin >> num; arr.push_back(num); } int sum = 1; k--; vector <int> arr2 = {}; for(int i = 0; i < n-1; i++) { arr2.push_back(arr[i+1]-arr[i]); sum += arr[i+1]-arr[i]; } sort(arr2.begin(), arr2.end(), greater<int>()); for(int i = 0; i < k; i++) { sum -= arr2[i]; } sum += k; cout << sum << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...