Submission #349830

#TimeUsernameProblemLanguageResultExecution timeMemory
349830shivensinha4Stove (JOI18_stove)C++17
100 / 100
25 ms2432 KiB
#include "bits/stdc++.h" using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' int main() { #ifdef mlocal freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<ll> nums(n); for_(i, 0, n) cin >> nums[i]; sort(nums.begin(), nums.end()); ll ans = 0; vector<ll> gap; for_(i, 1, n) gap.push_back(nums[i]-nums[i-1]-1); sort(gap.begin(), gap.end(), greater<>()); for_(i, 0, k-1) ans += gap[i]; cout << nums.back()+1-nums[0]-ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...