#include<bits/stdc++.h>
using namespace std;
#define int int64_t
int k, n, m, a, b, v[1010], s[5050], t[5050], dp[5050][5050][2][2];
void maximize(int &a, int b) {
if (a < b) a = b;
}
int32_t main() {
// freopen("FUNTOUR.inp", "r", stdin);
// freopen("FUNTOUR.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> k >> n >> m >> a >> b;
for(int i = 1; i <= k; i++) cin >> v[i];
for(int i = 1; i <= n; i++) cin >> s[i];
for(int i = 1; i <= m; i++) cin >> t[i];
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
dp[i][j][0][0] = max(dp[i][j - 1][0][0], dp[i - 1][j][0][0]) + b;
dp[i][j][0][1] = dp[i - 1][j][0][1] + b;
dp[i][j][1][0] = dp[i][j - 1][1][0] + b;
dp[i][j][1][1] = (j == 1 ? v[t[j]] : v[t[j]] + a);
maximize(dp[i][j][1][1], dp[i - 1][j - 1][0][0] + 2 * a + v[t[j]]);
maximize(dp[i][j][1][1], dp[i - 1][j - 1][0][1] + a + v[t[j]]);
maximize(dp[i][j][1][1], dp[i - 1][j - 1][1][0] + a + v[t[j]]);
maximize(dp[i][j][1][1], dp[i - 1][j - 1][1][1] + v[t[j]]);
}
}
int best = 0;
for(int i = 0; i <= 1; i++) {
for(int j = 0; j <= 1; j++) {
maximize(best, dp[n][m][i][j]);
}
}
cout << best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
17 ms |
30776 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
1 ms |
2004 KB |
Output is correct |
6 |
Correct |
6 ms |
10828 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
3 ms |
4308 KB |
Output is correct |
9 |
Correct |
11 ms |
18424 KB |
Output is correct |
10 |
Correct |
20 ms |
35796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
86968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
86968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
86968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1620 KB |
Output is correct |
2 |
Correct |
17 ms |
30776 KB |
Output is correct |
3 |
Correct |
1 ms |
1748 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
1 ms |
2004 KB |
Output is correct |
6 |
Correct |
6 ms |
10828 KB |
Output is correct |
7 |
Correct |
1 ms |
1492 KB |
Output is correct |
8 |
Correct |
3 ms |
4308 KB |
Output is correct |
9 |
Correct |
11 ms |
18424 KB |
Output is correct |
10 |
Correct |
20 ms |
35796 KB |
Output is correct |
11 |
Incorrect |
1 ms |
724 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |