#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<int, int> point;
const int mod = 1e9 + 7, inf = 1e9, MAXN = 505, off = 1 << 18;
int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}
int n, m, k;
int p[MAXN], val[MAXN];
ll dp[MAXN][MAXN];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> k;
REP(i, n) cin >> p[i];
REP(i, m + 1) cin >> val[i];
REP(i, min(k + 1, m - p[0] + 1)) dp[0][i] = val[ min(p[0] + i, m) ];
FOR(i, 1, n) REP(j, k + 1) REP(last, m - p[i] + 1){
if(j - last < 0) continue;
dp[i][j] = max(dp[i][j], dp[i - 1][j - last] + val[ p[i] + last ] );
}
cout << dp[n - 1][k];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2304 KB |
Output is correct |
2 |
Correct |
5 ms |
2304 KB |
Output is correct |
3 |
Correct |
130 ms |
2308 KB |
Output is correct |
4 |
Correct |
130 ms |
2352 KB |
Output is correct |
5 |
Correct |
131 ms |
2296 KB |
Output is correct |
6 |
Correct |
139 ms |
2392 KB |
Output is correct |
7 |
Correct |
136 ms |
2396 KB |
Output is correct |
8 |
Correct |
138 ms |
2328 KB |
Output is correct |
9 |
Correct |
133 ms |
2296 KB |
Output is correct |
10 |
Correct |
138 ms |
2268 KB |
Output is correct |