Submission #945396

#TimeUsernameProblemLanguageResultExecution timeMemory
945396KasymKStove (JOI18_stove)C++17
100 / 100
38 ms1472 KiB
#include "bits/stdc++.h" using namespace std; int main(){ int n, k; cin >> n >> k; vector<int> v(n); for(int &i : v) cin >> i; if(k == 1){ cout << v.back() + 1 - v.front() << "\n"; return 0; } // int div = ceil(n/2); // biz aralaryny yakynlasdyrjak bolyas int ans = v.back() + 1 - v.front(); vector<int> tap; for(int i = 0; i < n - 1; ++i){ int diff = abs(v[i + 1] - v[i]); tap.push_back(diff); } k--; sort(tap.rbegin(), tap.rend()); for(int i = 1; i <= k; ++i){ ans -= tap[i - 1]; ans++; } // ans += k; cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...