Submission #128219

#TimeUsernameProblemLanguageResultExecution timeMemory
128219wasylStove (JOI18_stove)C++11
100 / 100
28 ms2424 KiB
#include <bits/stdc++.h> using namespace std; constexpr int nax = 1e5; int n, k, tab[nax]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; ++i) cin >> tab[i]; sort(tab, tab + n); --k; vector< int > ilo; for (int i = 0; i < n - 1; ++i) ilo.push_back(tab[i + 1] - tab[i] - 1); sort(begin(ilo), end(ilo)); reverse(begin(ilo), end(ilo)); k = min(k, (int)ilo.size()); //cerr << tab[n - 1] + 1 << ' ' << tab[0] << ' ' << accumulate(ilo.end() - k, ilo.end(), 0) << '\n'; cout << tab[n - 1] + 1 - tab[0] - accumulate(ilo.begin(), ilo.begin() + k, 0) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...