#include <bits/stdc++.h>
#include <peru.h>
using namespace std;
#define Mod 1000000007
int solve ( int n, int k, int* v ){
long long int dp[n + 1];
dp[0] = 0;
for(int i = 1; i <= n; i++){
long long int maxi = v[i - 1];
dp[i] = LLONG_MAX;
//cout << "i = " << i << " maxi = " << maxi << endl;
for(int j = i - 1; j >= 0 && i - j <= k; j--){
dp[i] = min( dp[i], dp[j] + maxi );
//cout << " -- > j = " << j << " dp[j] = " << dp[j] << " maxi = " << maxi << endl;
maxi = max( (long long)v[j - 1], maxi );
}
}
/*
cout << "dp : ";
for(int i = 1; i <= n; i++) cout << dp[i] << " ";
cout << endl;
*/
long long int sum = 0;
long long int p = 1;
for(int i = n; i > 0; i--){
sum += (p * dp[i]) % Mod;
p *= 23;
p %= Mod;
}
return sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
500 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |