Submission #487730

#TimeUsernameProblemLanguageResultExecution timeMemory
487730stefantagaStove (JOI18_stove)C++14
100 / 100
17 ms2948 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 42, INF = 1e18; int a[N], b[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n-1; i++) b[i] = a[i+1] - a[i] - 1; sort(b, b + n - 1); int sum = n; for(int i = 0; i < n-k; i++) sum += b[i]; cout << sum; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...