Submission #870977

#TimeUsernameProblemLanguageResultExecution timeMemory
870977marcidStove (JOI18_stove)C++17
20 / 100
2 ms436 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> a(n+1, 0); vector<pair<int,int>> b(n+1, {0,0}); for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 1; i <= n; i++) { b[i].first = abs(a[i-1]-a[i])-1; b[i].second = i; } sort(b.rbegin(), b.rend()); int sum = a[n]-a[1]+1; for (int i = 0; i < k-1; i++) { sum -= b[i].first; } cout << sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...