Submission #440319

#TimeUsernameProblemLanguageResultExecution timeMemory
440319IdkwhoamiStove (JOI18_stove)C++17
100 / 100
55 ms3184 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n, k; cin >> n >> k; vector<ll> v(n), d; for(ll i = 0;i<n;i++){ cin >> v[i]; if(i != 0)d.push_back(v[i] - v[i-1]); } sort(d.begin(), d.end(), greater<ll>()); ll ans = v[n-1] - v[0] + k; for(ll i = 0;i<k-1;i++){ ans -= d[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...