Submission #946875

#TimeUsernameProblemLanguageResultExecution timeMemory
946875tnknguyen_Stove (JOI18_stove)C++17
100 / 100
19 ms4704 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' const int sz = 1e6 + 5; long long a[sz]; int n, k; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("main.inp","r",stdin); //freopen("main.out","w",stdout); cin >> n >> k; if(k == n){ cout << n; return 0; } vector<int> v; for(int i=1;i<=n;++i){ cin >> a[i]; if(i > 1){ v.push_back(a[i] - a[i-1] - 1); } } sort(v.begin(), v.end(), greater<int>()); long long ans = a[n] - a[1] + 1; for(int i=0;i<k-1;++i){ ans -= (v[i]); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...