Submission #127309

#TimeUsernameProblemLanguageResultExecution timeMemory
127309AuldLangSyneStove (JOI18_stove)C++14
100 / 100
28 ms2936 KiB
#include <bits/stdc++.h> #define ll long long #define f(i, a, b) for(ll i = a; i <= b; ++i) #define ff(i, a, b) for(ll i = a; i < b; ++i) #define F(i, a, b) for(ll i = a; i >= b; --i) #define FF(i, a, b) for(ll i = a; i > b; --i) #define x first #define y second #define X real() #define Y imag() using namespace std; typedef complex<ll> P; typedef pair<ll, ll> ii; typedef tuple<ll, ll, ll> iii; const ll N = 1e5+7; ll n, m, ans = 0, a[N]; vector<ll> arr; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; f(i,1,n){ cin >> a[i]; } ans += n; sort(a+1, a+1+n); ff(i,1,n){ arr.push_back(a[i+1] - a[i] - 1); ans += a[i+1] - a[i] - 1; } sort(arr.begin(), arr.end(), less<ll>()); m-=1; while(m && arr.size()){ ans -= arr.back(); m--; arr.pop_back(); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...