This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int ans = 1e9;
void f(int i, int k, int n, vector <int> a, int sum) {
if (k < 0) return;
if (i == n - 1) ans = min(ans, sum);
if (i == n - 1) return;
f(i + 1, k, n, a, sum + (a[i + 1] - a[i]));
f(i + 1, k - 1, n, a, sum + 1);
}
signed main() {
int n, k;
cin >> n >> k;
vector <int> a(n);
for (int i = 0; i < n; i ++) cin >> a[i];
f(0, k-1, n, a, 1);
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |