Submission #154699

#TimeUsernameProblemLanguageResultExecution timeMemory
154699jovan_bStove (JOI18_stove)C++17
100 / 100
26 ms2168 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int niz[100005]; int g[100005]; int main(){ ios_base::sync_with_stdio(false); cout.precision(10); cout<<fixed; int n, k; cin >> n >> k; k--; for(int i=1; i<=n; i++){ cin >> niz[i]; } for(int i=2; i<=n; i++){ g[i] = niz[i] - niz[i-1] - 1; } sort(g+1, g+1+n); reverse(g+1, g+1+n); int res = niz[n]+1-niz[1]; for(int i=1; i<=k; i++) res -= g[i]; cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...