# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37925 | Just_Solve_The_Problem | K blocks (IZhO14_blocks) | C++11 | 1000 ms | 5140 KiB |
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 ll long long
const int N = (int)1e5 + 7;
int a[N];
ll ans = 1e14;
int n, k;
vector < int > dns;
void go (int pos, int mx, ll sum = 0, int kk = 1, vector < int > vec = vector < int > ()) {
mx = max(mx, a[pos]);
if (pos == n + 1) {
if (kk == k) {
if (ans > sum + mx) {
ans = sum + mx;
dns = vec;
}
}
return ;
}
if (kk + 1 <= k && pos != n) {
vec.push_back(pos);
go(pos + 1, 0, sum + mx, kk + 1, vec);
vec.pop_back();
}
go(pos + 1, mx, sum, kk, vec);
}
main() {
scanf ("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf ("%d", a + i);
}
go(1, 0);
cout << ans << endl;
// for (int to : dns) {
// cout << to << ' ' ;
// }
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |