#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
typedef long long i64;
using namespace std;
const int N = 5e3 + 5;
int cur [N][2][2];
int nxt [N][2][2];
int k, n, m, a, b;
int felicidade_evento [N];
int dia_evento [N];
int tarefas [N];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k >> n >> m >> a >> b;
for (int i = 1; i <= k; i++) cin >> felicidade_evento[i];
for (int i = 0; i < n; i++) cin >> dia_evento[i];
for (int i = 0; i < m; i++) cin >> tarefas[i];
for (int j = 0; j < N; j++) {
nxt[j][0][0] = cur[j][0][0] = -1e9;
nxt[j][0][1] = cur[j][0][1] = -1e9;
nxt[j][1][0] = cur[j][1][0] = -1e9;
nxt[j][1][1] = cur[j][1][1] = -1e9;
}
cur[0][0][0] = nxt[0][0][0] = 0;
// Day / Task / Jump Task / Jump day
int mn = a + (m * b);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
if (tarefas[j] == dia_evento[i]) {
nxt[j + 1][0][0] = max (nxt[j + 1][0][0], cur[j][x][y] + felicidade_evento[tarefas[j]]);
}
}
}
for (int x = 0; x < 2; x++) {
// Start to jump task
cur[j + 1][1][x] = max (cur[j + 1][1][x], cur[j][0][x] + a + b);
// Continue to jump task
cur[j + 1][1][x] = max (cur[j + 1][1][x], cur[j][1][x] + b);
}
for (int x = 0; x < 2; x++) {
// Start to jump day
nxt[j][x][1] = max (nxt[j][x][1], cur[j][x][0] + a + b);
// Continue to jump day
nxt[j][x][1] = max (nxt[j][x][1], cur[j][x][1] + b);
}
}
for (int j = 0; j < m; j++) {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
mn = max (mn, cur[m][x][y]);
cur[j][x][y] = nxt[j][x][y];
mn = max (mn, nxt[m][x][y]);
}
}
}
for (int j = 0; j < N; j++) {
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
nxt[j][0][0] = -1e9;
nxt[j][0][1] = -1e9;
nxt[j][1][0] = -1e9;
nxt[j][1][1] = -1e9;
}
}
}
cur[0][0][0] = 0;
nxt[0][0][0] = 0;
}
cout << mn << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
24 ms |
512 KB |
Output is correct |
3 |
Correct |
7 ms |
512 KB |
Output is correct |
4 |
Correct |
12 ms |
512 KB |
Output is correct |
5 |
Correct |
8 ms |
512 KB |
Output is correct |
6 |
Correct |
14 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
19 ms |
512 KB |
Output is correct |
10 |
Correct |
28 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
11 ms |
512 KB |
Output is correct |
4 |
Correct |
6 ms |
512 KB |
Output is correct |
5 |
Correct |
7 ms |
512 KB |
Output is correct |
6 |
Correct |
17 ms |
512 KB |
Output is correct |
7 |
Correct |
16 ms |
512 KB |
Output is correct |
8 |
Correct |
21 ms |
512 KB |
Output is correct |
9 |
Correct |
8 ms |
512 KB |
Output is correct |
10 |
Correct |
27 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
660 KB |
Output is correct |
2 |
Correct |
36 ms |
572 KB |
Output is correct |
3 |
Correct |
130 ms |
512 KB |
Output is correct |
4 |
Correct |
277 ms |
584 KB |
Output is correct |
5 |
Incorrect |
88 ms |
512 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
660 KB |
Output is correct |
2 |
Correct |
36 ms |
572 KB |
Output is correct |
3 |
Correct |
130 ms |
512 KB |
Output is correct |
4 |
Correct |
277 ms |
584 KB |
Output is correct |
5 |
Incorrect |
88 ms |
512 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
660 KB |
Output is correct |
2 |
Correct |
36 ms |
572 KB |
Output is correct |
3 |
Correct |
130 ms |
512 KB |
Output is correct |
4 |
Correct |
277 ms |
584 KB |
Output is correct |
5 |
Incorrect |
88 ms |
512 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Correct |
5 ms |
512 KB |
Output is correct |
14 |
Correct |
6 ms |
512 KB |
Output is correct |
15 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
512 KB |
Output is correct |
2 |
Correct |
24 ms |
512 KB |
Output is correct |
3 |
Correct |
7 ms |
512 KB |
Output is correct |
4 |
Correct |
12 ms |
512 KB |
Output is correct |
5 |
Correct |
8 ms |
512 KB |
Output is correct |
6 |
Correct |
14 ms |
512 KB |
Output is correct |
7 |
Correct |
6 ms |
512 KB |
Output is correct |
8 |
Correct |
9 ms |
512 KB |
Output is correct |
9 |
Correct |
19 ms |
512 KB |
Output is correct |
10 |
Correct |
28 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
512 KB |
Output is correct |
13 |
Correct |
11 ms |
512 KB |
Output is correct |
14 |
Correct |
6 ms |
512 KB |
Output is correct |
15 |
Correct |
7 ms |
512 KB |
Output is correct |
16 |
Correct |
17 ms |
512 KB |
Output is correct |
17 |
Correct |
16 ms |
512 KB |
Output is correct |
18 |
Correct |
21 ms |
512 KB |
Output is correct |
19 |
Correct |
8 ms |
512 KB |
Output is correct |
20 |
Correct |
27 ms |
512 KB |
Output is correct |
21 |
Correct |
56 ms |
660 KB |
Output is correct |
22 |
Correct |
36 ms |
572 KB |
Output is correct |
23 |
Correct |
130 ms |
512 KB |
Output is correct |
24 |
Correct |
277 ms |
584 KB |
Output is correct |
25 |
Incorrect |
88 ms |
512 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |