Submission #1274714

#TimeUsernameProblemLanguageResultExecution timeMemory
1274714muhammad-ahmadStove (JOI18_stove)C++20
100 / 100
38 ms2332 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' signed main(){ int n, k; cin >> n >> k; int ans = 0, a[n + 1]; a[0] = -1; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); vector<int> dif; for (int i = 1; i <= n; i++){ if (a[i] - a[i - 1] != 1) { ans++; if (i > 1) dif.push_back(a[i] - a[i - 1] - 1); } } int l = n; sort(dif.rbegin(), dif.rend()); while (ans > k){ ans--; l += dif.back(); dif.pop_back(); } cout << l << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...