Submission #1241944

#TimeUsernameProblemLanguageResultExecution timeMemory
1241944i_lov_arisStove (JOI18_stove)C++20
100 / 100
12 ms1892 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int MAXN = 100000; int n, k; int a[MAXN + 5]; int d[MAXN + 5]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } int total = a[n] + 1 - a[1]; for(int i = 1; i < n; i++){ d[i] = a[i + 1] - a[i] - 1; } sort(d + 1, d + n, greater<int>()); int s = 0; for(int i = 1; i <= k - 1; i++){ s += d[i]; } cout << total - s; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...