Submission #545426

#TimeUsernameProblemLanguageResultExecution timeMemory
545426LunaMemeStove (JOI18_stove)C++14
100 / 100
49 ms1832 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; typedef vector<int> vi; typedef long long ll; #define PB push_back #define MP make_pair #define FOR(i, x, y) for (int i = x; i < y ; i ++) int main(){ int n, k; cin >> n >> k; int prev; int first; vi gaps; cin >> prev; first = prev; FOR(i, 0, n - 1){ int num; cin >> num; gaps.PB(num - prev - 1); prev = num; } sort(gaps.rbegin(), gaps.rend()); ll ans = prev - first + 1; FOR(i, 0, k - 1){ ans -= gaps[i]; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...