Submission #1101412

#TimeUsernameProblemLanguageResultExecution timeMemory
1101412nguyenphuoclocK blocks (IZhO14_blocks)C++14
53 / 100
65 ms88396 KiB
#include<bits/stdc++.h>
#define ll long long
#define MASK(i) (1 << (i))
using namespace std;
const int N = 1e5 + 5;
int n, d, a[N], c[N][22], dp[105][100005];
int get(int l, int r) {
  int h = log2(r - l + 1);
  return max(c[l][h], c[r - MASK(h) + 1][h]);
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> d;
  for(int i = 1; i <= n; i++) cin >> a[i], c[i][0] = a[i];
  for(int j = 1; MASK(j) <= n; j++)
    for(int i = 1; i + MASK(j) - 1 <= n; i++)
      c[i][j] = max(c[i][j - 1], c[i + MASK(j - 1)][j - 1]);
  memset(dp, 0x3f, sizeof dp);
  dp[0][0] = 0;
  for(int j = 1; j <= d; j++) {
    for(int i = j; i <= n; i++) {
      for(int k = 1; k <= i; k++) {
        dp[i][j] = min(dp[i][j], dp[k - 1][j - 1] + get(k, i));
      }
    }
  }
  cout << dp[n][d];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...