Submission #207819

#TimeUsernameProblemLanguageResultExecution timeMemory
207819opukittpceno_hhrStove (JOI18_stove)C++17
100 / 100
31 ms2424 KiB
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <random> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); for (auto &t : a) { cin >> t; } sort(a.begin(), a.end()); int ans = a.back() - a.front() + 1; vector<int> dl; for (int i = 1; i < n; i++) dl.push_back(a[i] - a[i - 1] - 1); sort(dl.rbegin(), dl.rend()); for (int i = 0; i < k - 1; i++) ans -= dl[i]; cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...