Submission #369099

#TimeUsernameProblemLanguageResultExecution timeMemory
369099shafinalamStove (JOI18_stove)C++14
100 / 100
55 ms2404 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int mxn = 2e5+5; ll arr[mxn]; int main() { int n, k; cin >> n >> k; for(int i = 1; i <= n; i++) cin >> arr[i]; sort(arr+1, arr+n+1); vector<ll>v; ll sum = 0; for(int i = 2; i <= n; i++) { ll d = arr[i]-arr[i-1]-1; v.push_back(arr[i]-arr[i-1]-1); sum+=d; } sort(v.rbegin(), v.rend()); /* for(auto it : v) { cout << it << ' '; } cout << '\n'; */ int x = min((int)v.size(), k-1); for(int i = 0; i < x; i++) { sum-=v[i]; } sum+=n; cout << sum << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...