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>
#include "peru.h"
using namespace std;
const int NMAX = 2500000;
const int MOD = 1e9 + 7;
long long dp[NMAX];
int solve( int n, int k, int* v ) {
deque <int> dq;
int ans = 0;
for ( int i = 0; i < n; i ++ ) {
dp[i] = v[i] + ( i > 0 ? dp[i - 1] : 0 );
for ( int j = i, maxSuf = 0; j >= max( 0, i - k + 1 ); j -- ) {
maxSuf = max( maxSuf, v[j] );
dp[i] = min( dp[i], maxSuf + ( j == 0 ? 0 : dp[j - 1] ) );
}
// while ( !dq.empty() && v[dq.back()] <= v[i] ) dq.pop_back();
// dq.push_back( i );
// dp[i] = v[dq.front()] + ( i >= k ? dp[i - k] : 0 );
// for ( int j = 1; j < (int)dq.size(); j ++ ) {
// dp[i] = min( dp[i], dp[dq[j - 1]] + v[dq[j]] );
// }
ans = ( (long long)ans * 23 + dp[i] ) % MOD;
}
dq.clear();
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... |