Submission #988963

#TimeUsernameProblemLanguageResultExecution timeMemory
988963MuhammetStove (JOI18_stove)C++17
100 / 100
15 ms2468 KiB
#include <bits/stdc++.h> using namespace std; #define N 300005 #define ll long long int #define sz(x) (int)x.size() #define ff first #define ss second int T, n, a[N], k; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } sort(a+1,a+n+1); vector <int> v; for(int i = 1; i < n; i++){ v.push_back(a[i+1]-a[i]-1); } sort(v.rbegin(), v.rend()); int ans = n; k -= n; while(sz(v) > 0 and k < 0){ k++; ans += v.back(); v.pop_back(); } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...