Submission #1298382

#TimeUsernameProblemLanguageResultExecution timeMemory
1298382baldyStove (JOI18_stove)C++20
100 / 100
15 ms2448 KiB
#include <bits/stdc++.h> using namespace std; void solve() { long long n,k; cin >> n >> k; vector<long long> ans(n); // ans.push_back(0); // ans.push_back(1e9); for(int i= 0;i < n;i++){ cin >> ans[i]; } sort(ans.begin(),ans.end()); int need = n - k; //int m = ans.size(); vector<long long> diff; int output = n; for(int i =1;i < n;i++){ diff.push_back(max(0LL,ans[i] - ans[i - 1] - 1)); } sort(diff.begin(),diff.end()); for(int i= 0;i < min((int)diff.size(),need);i++){ if(diff[i] > 0) output+=diff[i]; } cout << output << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...