Submission #1114763

#TimeUsernameProblemLanguageResultExecution timeMemory
1114763Isa2011Stove (JOI18_stove)C++14
100 / 100
26 ms2040 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); int n,k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); int h = n - k; if (n == k) cout << n; else if (k == 1) cout << a[n-1]; else { vector<int> l(n-1); for (int i = 0; i < n-1; i++) l[i] = a[i+1] - a[i]; sort(l.begin(), l.end()); int ans = n - h; for (int i = 0; i < h; i++) ans += l[i]; cout << ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...