#include <bits/stdc++.h>
#include "peru.h"
using namespace std;
using i64 = long long;
const int MOD = 1e9 + 7;
i64 add(i64 x,i64 y){
return (x % MOD + y % MOD) % MOD;
}
i64 mul(i64 x,i64 y){
return (x % MOD * (y % MOD)) % MOD;
}
int solve(int n, int k, int* v){
vector<i64> dp(n + 1,2e18);
i64 mx = 0;
for (int i = 0; i < k-1; i++){
mx = max(mx,(i64) v[i]);
dp[i] = mx;
cerr << dp[i] << " ";
}
for (int i = k-1; i < n; i++){
mx = v[i];
for (int j = i-1; j >= max(i - k,0); j--){
dp[i] = min(dp[i], add(dp[j],mx));
mx = max(mx,(i64) v[j]);
}
cerr << dp[i] << " ";
}
i64 pw = 1,ans = 0;
for (int i = n-1; i > -1; i--){
ans = add(ans,mul(dp[i],pw));
pw = mul(pw,23);
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |