Submission #230164

#TimeUsernameProblemLanguageResultExecution timeMemory
230164Haunted_CppStove (JOI18_stove)C++17
100 / 100
32 ms2432 KiB
#include <iostream> #include <queue> #include <algorithm> using namespace std; const int N = 1e5 + 5; int a [N]; int main () { ios::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; sort (a, a + n); int res = a[n - 1] - a[0] + 1; --k; vector<int> dis; int rem = 0; for (int i = 1; i < n; i++) { dis.emplace_back(a[i] - a[i - 1] - 1); } sort (dis.rbegin(), dis.rend()); for (int i = 0; i < min (k, (int) dis.size()); i++) { rem += dis[i]; } cout << res - rem << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...