Submission #55248

#TimeUsernameProblemLanguageResultExecution timeMemory
55248shoemakerjoStove (JOI18_stove)C++14
100 / 100
39 ms10532 KiB
#include <bits/stdc++.h> using namespace std; #define maxn 100010 int n, k; int nums[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int ans = 0; vector<int> diffs; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> nums[i]; if (i) ans += nums[i]-nums[i-1]; if (i) diffs.push_back(nums[i]-nums[i-1]-1); } ans++; //need to be one past the end sort(diffs.begin(), diffs.end()); reverse(diffs.begin(), diffs.end()); for (int i = 0; i < k-1; i++) { ans -= diffs[i]; } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...