Submission #586714

#TimeUsernameProblemLanguageResultExecution timeMemory
586714VanillaStove (JOI18_stove)C++17
100 / 100
52 ms2772 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int maxn = 2e5 + 2; int main() { int n,k; cin >> n >> k; vector <int64> a (n); vector <int64> diff (n - 1); for (int i = 0; i < n; i++){ cin >> a[i]; if (i != 0) diff[i-1] = a[i] - a[i-1] - 1; } int64 rs = a[n-1] - a[0] + 1; sort(diff.begin(), diff.end(), [] (int64 &a, int64 &b) { return a > b; }); for (int i = 0; i < k - 1; i++){ rs-=diff[i]; } cout << rs << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...