Submission #1124497

#TimeUsernameProblemLanguageResultExecution timeMemory
1124497LucaIlieStove (JOI18_stove)C++20
100 / 100
36 ms964 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k, a; int cost = 1; vector<int> v; cin >> n >> k; for ( int i = 1; i <= n; i++ ) { int b; cin >> b; if ( i > 1 ) { v.push_back( b - a - 1 ); cost += b - a; } a = b; } sort( v.begin(), v.end() ); reverse( v.begin(), v.end() ); for ( int i = 0; i < k - 1; i++ ) cost -= v[i]; cout << cost; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...