Submission #659319

#TimeUsernameProblemLanguageResultExecution timeMemory
659319illyakrStove (JOI18_stove)C++14
100 / 100
44 ms3196 KiB
#include <iostream> #include <vector> #include <algorithm> #define int long long using namespace std; int n, k; int t[101010]; int res = 0; vector<int> dif; int32_t main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> t[i]; for (int i = 2; i <= n; i++) { dif.push_back(t[i] - t[i - 1]); } res = t[n] - t[1] + 1; sort(dif.begin(), dif.end(), greater<int>()); for (int i = 0; i + 1 < k; i++) { res -= dif[i]; res++; } cout << res; } /** 3 2 1 3 6 3 1 1 3 6 10 5 1 2 5 6 8 11 13 15 16 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...