#include <stdio.h>
#define N 5000
#define M 5000
#define K 1000
#define INF 0x3f3f3f3f
int max(int a, int b) { return a > b ? a : b; }
int main() {
static int aa[N], bb[M], ww[K], dp[M + 1][2][2], dq[M + 1][2][2];
int n, m, k, a, b, i, j, c, u, v, ans;
scanf("%d%d%d%d%d", &k, &n, &m, &a, &b);
for (c = 0; c < k; c++)
scanf("%d", &ww[c]);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]), aa[i]--;
for (j = 0; j < m; j++)
scanf("%d", &bb[j]), bb[j]--;
for (j = 0; j <= m; j++)
for (u = 0; u < 2; u++)
for (v = 0; v < 2; v++)
dp[j][u][v] = -INF;
ans = -INF;
for (i = 0; i <= n; i++) {
for (j = 0; j <= m; j++)
for (u = 0; u < 2; u++)
for (v = 0; v < 2; v++)
dq[j][u][v] = -INF;
dp[0][0][0] = max(dp[0][0][0], 0);
for (j = 0; j <= m; j++)
for (u = 0; u < 2; u++)
for (v = 0; v < 2; v++) {
int x = dp[j][u][v];
if (x == -INF)
continue;
if (i < n)
dq[j][0][v] = max(dq[j][0][v], x + (u == 1 ? a : 0) + b);
if (j < m)
dp[j + 1][u][0] = max(dp[j + 1][u][0], x + a + (v == 1 ? b : 0));
if (i < n && j < m && aa[i] == bb[j])
dq[j + 1][1][1] = max(dq[j + 1][1][1], x + ww[aa[i]]);
}
for (u = 0; u < 2; u++)
for (v = 0; v < 2; v++)
ans = max(ans, dp[m][u][v]);
for (j = 0; j <= m; j++)
for (u = 0; u < 2; u++)
for (v = 0; v < 2; v++)
dp[j][u][v] = dq[j][u][v];
}
printf("%d\n", ans);
return 0;
}
Compilation message
VisitingSingapore.c: In function 'main':
VisitingSingapore.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%d%d%d%d", &k, &n, &m, &a, &b);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
VisitingSingapore.c:16:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &ww[c]);
| ^~~~~~~~~~~~~~~~~~~
VisitingSingapore.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d", &aa[i]), aa[i]--;
| ^~~~~~~~~~~~~~~~~~~
VisitingSingapore.c:20:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d", &bb[j]), bb[j]--;
| ^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
296 KB |
Output is correct |
9 |
Correct |
11 ms |
300 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
336 KB |
Output is correct |
3 |
Correct |
97 ms |
384 KB |
Output is correct |
4 |
Correct |
242 ms |
492 KB |
Output is correct |
5 |
Correct |
74 ms |
440 KB |
Output is correct |
6 |
Correct |
119 ms |
340 KB |
Output is correct |
7 |
Correct |
205 ms |
340 KB |
Output is correct |
8 |
Correct |
63 ms |
340 KB |
Output is correct |
9 |
Correct |
130 ms |
336 KB |
Output is correct |
10 |
Correct |
317 ms |
504 KB |
Output is correct |
11 |
Correct |
325 ms |
500 KB |
Output is correct |
12 |
Correct |
317 ms |
500 KB |
Output is correct |
13 |
Correct |
268 ms |
480 KB |
Output is correct |
14 |
Correct |
416 ms |
480 KB |
Output is correct |
15 |
Correct |
389 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
336 KB |
Output is correct |
3 |
Correct |
97 ms |
384 KB |
Output is correct |
4 |
Correct |
242 ms |
492 KB |
Output is correct |
5 |
Correct |
74 ms |
440 KB |
Output is correct |
6 |
Correct |
119 ms |
340 KB |
Output is correct |
7 |
Correct |
205 ms |
340 KB |
Output is correct |
8 |
Correct |
63 ms |
340 KB |
Output is correct |
9 |
Correct |
130 ms |
336 KB |
Output is correct |
10 |
Correct |
317 ms |
504 KB |
Output is correct |
11 |
Correct |
325 ms |
500 KB |
Output is correct |
12 |
Correct |
317 ms |
500 KB |
Output is correct |
13 |
Correct |
268 ms |
480 KB |
Output is correct |
14 |
Correct |
416 ms |
480 KB |
Output is correct |
15 |
Correct |
389 ms |
480 KB |
Output is correct |
16 |
Incorrect |
167 ms |
436 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
344 KB |
Output is correct |
2 |
Correct |
12 ms |
336 KB |
Output is correct |
3 |
Correct |
97 ms |
384 KB |
Output is correct |
4 |
Correct |
242 ms |
492 KB |
Output is correct |
5 |
Correct |
74 ms |
440 KB |
Output is correct |
6 |
Correct |
119 ms |
340 KB |
Output is correct |
7 |
Correct |
205 ms |
340 KB |
Output is correct |
8 |
Correct |
63 ms |
340 KB |
Output is correct |
9 |
Correct |
130 ms |
336 KB |
Output is correct |
10 |
Correct |
317 ms |
504 KB |
Output is correct |
11 |
Correct |
325 ms |
500 KB |
Output is correct |
12 |
Correct |
317 ms |
500 KB |
Output is correct |
13 |
Correct |
268 ms |
480 KB |
Output is correct |
14 |
Correct |
416 ms |
480 KB |
Output is correct |
15 |
Correct |
389 ms |
480 KB |
Output is correct |
16 |
Incorrect |
239 ms |
472 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
13 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
296 KB |
Output is correct |
9 |
Correct |
11 ms |
300 KB |
Output is correct |
10 |
Correct |
15 ms |
348 KB |
Output is correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |