#include <bits/stdc++.h>
using namespace std;
#include "peru.h"
#define ll long long
const ll p = 1e9+7;
int solve(int n, int k, int* v){
vector<ll> dp(n);
function<ll(int)> get = [&](int idx) {
if (idx < 0) return 0ll;
return dp[idx];
};
for (int i = 0; i < n; i++) {
ll curmin = 1e18;
int runmax = v[i];
for (int j = i-1; j >= i-k; j--) {
curmin = min(curmin, ((ll)get(j) + (ll)runmax));
if (j < 0) break;
runmax = max(runmax, v[j]);
}
dp[i] = curmin;
}
ll factor = 1;
ll res = 0;
for (int i = n-1; i >= 0; i--) {
res += ((dp[i]%p)*factor) % p;
res %= p;
factor *= 23;
factor %= p;
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |