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>
#define ll long long
using namespace std;
//ifstream in("input.peru10");
//ofstream out("out.out");
const int nmax = 2500000;
const int P = 1000000007;
ll dp[nmax];
int solve(int n, int k, int* s) {
for (int i = 1; i <= n; i++) dp[i] = LLONG_MAX;
for (int i = 1; i <= n; i++) {
int maxSoFar = -1;
for (int j = i - 1; j >= 0 && j >= i - k; j--) {
maxSoFar = max(maxSoFar, s[j]);
dp[i] = min(dp[i], (dp[j] + maxSoFar));
}
}
ll put23 = 1;
ll sum = 0;
for (int i = n; i >= 1; i--) {
sum = (sum + dp[i] * put23 % P) % P;
put23 = ( put23 * 23 ) % P;
}
return sum;
}
/*int s[nmax];
int main() {
int n,k;
in >> n >> k;
for (int i = 0; i < n; i++) in >> s[i];
out << solve(n , k , s);
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |