Submission #1105055

#TimeUsernameProblemLanguageResultExecution timeMemory
1105055haianhnguyen08102007Stove (JOI18_stove)C++17
100 / 100
19 ms3448 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e5+5; int n, k, a[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>k; for (int i=1; i<=n; i++) cin>>a[i]; sort(a+1, a+1+n); int sum = a[n] - a[1] + 1; vector <int> v; v.clear(); for (int i=2; i<=n; i++) v.push_back(a[i]-a[i-1]-1); sort(v.begin(), v.end()); for (int i=1; i<k; i++) sum-=v[(v.size()-i)]; cout<<sum; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...