#include <bits/stdc++.h>
using namespace std;
int main(){
int k,n,m,a,b;
cin >> k >> n >> m >> a >> b;
int v[k+5];
for (int i=1; i<=k; i++) cin >> v[i];
int day[n+5];
for (int i=1; i<=n; i++) cin >> day[i];
int ord[m+5];
for (int i=1; i<=m; i++) cin >> ord[i];
int dp[2][m+5][2];
for (int i=0; i<2; i++){
for (int j=0; j<m+5; j++){
dp[i][j][0] = -1e9 - 200;
dp[i][j][1] = -1e9 - 200;
}
}
dp[0][0][0] = 0;
dp[0][0][1] = 0;
dp[1][0][0] = 0;
dp[1][0][1] = 0;
int storage[n+5][m+5];
for (int i=0; i<(m+5); i++) storage[0][i] = max(dp[0][i][0],dp[0][i][1]);
/*for (int i=1; i<=n; i++){
dp[i][0][0] = 0;
dp[i][0][1] = 0; //you don't need to go to singapore yet.
}*/
int bst[n+5][m+5];
for (int j=1; j<=m; j++){
bst[0][j] = (j*b); //you have jumped some event
}
bst[0][0] = -1e9 - 200; //not possible if jump
//cout << "HEHE" << endl;
for (int i=1; i<=n; i++){
for (int j=1; j<=m; j++){
dp[1][j][0] = max(dp[0][j][0] + b,dp[0][j][1] + a + b);
if (day[i]==ord[j]){
dp[1][j][1] = max(bst[i-1][j-1] + a, max(dp[0][j-1][1],dp[0][j-1][0])) + v[day[i]];
}
else dp[1][j][1] = -1e9 - 200;
}
bst[i][0] = -1e9 - 200; //impossible if jump forced
for (int j=1; j<=m; j++){
bst[i][j] = max(bst[i][j-1]+b, max(dp[1][j-1][1],dp[1][j-1][0])+b);
}
for (int j=0; j<=m; j++) storage[i][j] = max(dp[1][j][0],dp[1][j][1]);
for (int j=0; j<=m; j++) dp[0][j][0] = dp[1][j][0], dp[0][j][1] = dp[1][j][1];
}
int mx = -1e9 - 200;
for (int i=0; i<=n; i++){
for (int j=0; j<=m; j++){
int val = storage[i][j] + a + (m-j)*b;
if (j==m) val -= a;
mx = max(mx,val);
}
}
/*for (int i=0; i<=n; i++){
for (int j=0; j<=m; j++){
cout << "(" << dp[i][j][0] << ',' << dp[i][j][1] << ") ";
}
cout << endl;
}*/
int nov= a + (b*m);
cout << max(mx,nov);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
6948 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
2124 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
6 ms |
4044 KB |
Output is correct |
10 |
Correct |
13 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
2124 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
844 KB |
Output is correct |
6 |
Correct |
7 ms |
4064 KB |
Output is correct |
7 |
Correct |
7 ms |
4044 KB |
Output is correct |
8 |
Correct |
11 ms |
5708 KB |
Output is correct |
9 |
Correct |
2 ms |
844 KB |
Output is correct |
10 |
Correct |
13 ms |
8244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
19276 KB |
Output is correct |
2 |
Correct |
11 ms |
7972 KB |
Output is correct |
3 |
Correct |
83 ms |
64716 KB |
Output is correct |
4 |
Correct |
203 ms |
156676 KB |
Output is correct |
5 |
Correct |
62 ms |
45772 KB |
Output is correct |
6 |
Correct |
90 ms |
66804 KB |
Output is correct |
7 |
Correct |
166 ms |
124644 KB |
Output is correct |
8 |
Correct |
53 ms |
40780 KB |
Output is correct |
9 |
Correct |
100 ms |
79920 KB |
Output is correct |
10 |
Correct |
245 ms |
195612 KB |
Output is correct |
11 |
Correct |
258 ms |
195140 KB |
Output is correct |
12 |
Correct |
251 ms |
196160 KB |
Output is correct |
13 |
Correct |
251 ms |
196144 KB |
Output is correct |
14 |
Correct |
368 ms |
195740 KB |
Output is correct |
15 |
Correct |
296 ms |
195588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
19276 KB |
Output is correct |
2 |
Correct |
11 ms |
7972 KB |
Output is correct |
3 |
Correct |
83 ms |
64716 KB |
Output is correct |
4 |
Correct |
203 ms |
156676 KB |
Output is correct |
5 |
Correct |
62 ms |
45772 KB |
Output is correct |
6 |
Correct |
90 ms |
66804 KB |
Output is correct |
7 |
Correct |
166 ms |
124644 KB |
Output is correct |
8 |
Correct |
53 ms |
40780 KB |
Output is correct |
9 |
Correct |
100 ms |
79920 KB |
Output is correct |
10 |
Correct |
245 ms |
195612 KB |
Output is correct |
11 |
Correct |
258 ms |
195140 KB |
Output is correct |
12 |
Correct |
251 ms |
196160 KB |
Output is correct |
13 |
Correct |
251 ms |
196144 KB |
Output is correct |
14 |
Correct |
368 ms |
195740 KB |
Output is correct |
15 |
Correct |
296 ms |
195588 KB |
Output is correct |
16 |
Correct |
138 ms |
102212 KB |
Output is correct |
17 |
Correct |
165 ms |
123436 KB |
Output is correct |
18 |
Correct |
139 ms |
109700 KB |
Output is correct |
19 |
Correct |
30 ms |
22412 KB |
Output is correct |
20 |
Correct |
105 ms |
78020 KB |
Output is correct |
21 |
Correct |
6 ms |
4556 KB |
Output is correct |
22 |
Correct |
33 ms |
25164 KB |
Output is correct |
23 |
Correct |
64 ms |
49480 KB |
Output is correct |
24 |
Correct |
23 ms |
17740 KB |
Output is correct |
25 |
Correct |
259 ms |
195592 KB |
Output is correct |
26 |
Correct |
248 ms |
195492 KB |
Output is correct |
27 |
Correct |
251 ms |
196388 KB |
Output is correct |
28 |
Correct |
254 ms |
195560 KB |
Output is correct |
29 |
Correct |
304 ms |
195100 KB |
Output is correct |
30 |
Correct |
291 ms |
195232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
19276 KB |
Output is correct |
2 |
Correct |
11 ms |
7972 KB |
Output is correct |
3 |
Correct |
83 ms |
64716 KB |
Output is correct |
4 |
Correct |
203 ms |
156676 KB |
Output is correct |
5 |
Correct |
62 ms |
45772 KB |
Output is correct |
6 |
Correct |
90 ms |
66804 KB |
Output is correct |
7 |
Correct |
166 ms |
124644 KB |
Output is correct |
8 |
Correct |
53 ms |
40780 KB |
Output is correct |
9 |
Correct |
100 ms |
79920 KB |
Output is correct |
10 |
Correct |
245 ms |
195612 KB |
Output is correct |
11 |
Correct |
258 ms |
195140 KB |
Output is correct |
12 |
Correct |
251 ms |
196160 KB |
Output is correct |
13 |
Correct |
251 ms |
196144 KB |
Output is correct |
14 |
Correct |
368 ms |
195740 KB |
Output is correct |
15 |
Correct |
296 ms |
195588 KB |
Output is correct |
16 |
Correct |
207 ms |
163212 KB |
Output is correct |
17 |
Correct |
106 ms |
75036 KB |
Output is correct |
18 |
Correct |
34 ms |
23372 KB |
Output is correct |
19 |
Correct |
8 ms |
6156 KB |
Output is correct |
20 |
Correct |
5 ms |
3200 KB |
Output is correct |
21 |
Correct |
7 ms |
4700 KB |
Output is correct |
22 |
Correct |
101 ms |
75160 KB |
Output is correct |
23 |
Correct |
19 ms |
14224 KB |
Output is correct |
24 |
Correct |
171 ms |
132856 KB |
Output is correct |
25 |
Correct |
272 ms |
195396 KB |
Output is correct |
26 |
Correct |
247 ms |
195524 KB |
Output is correct |
27 |
Correct |
268 ms |
195416 KB |
Output is correct |
28 |
Correct |
273 ms |
195212 KB |
Output is correct |
29 |
Correct |
297 ms |
195584 KB |
Output is correct |
30 |
Correct |
342 ms |
195652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
12 ms |
6948 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
2124 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
6 ms |
4044 KB |
Output is correct |
10 |
Correct |
13 ms |
8140 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
2124 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
844 KB |
Output is correct |
16 |
Correct |
7 ms |
4064 KB |
Output is correct |
17 |
Correct |
7 ms |
4044 KB |
Output is correct |
18 |
Correct |
11 ms |
5708 KB |
Output is correct |
19 |
Correct |
2 ms |
844 KB |
Output is correct |
20 |
Correct |
13 ms |
8244 KB |
Output is correct |
21 |
Correct |
25 ms |
19276 KB |
Output is correct |
22 |
Correct |
11 ms |
7972 KB |
Output is correct |
23 |
Correct |
83 ms |
64716 KB |
Output is correct |
24 |
Correct |
203 ms |
156676 KB |
Output is correct |
25 |
Correct |
62 ms |
45772 KB |
Output is correct |
26 |
Correct |
90 ms |
66804 KB |
Output is correct |
27 |
Correct |
166 ms |
124644 KB |
Output is correct |
28 |
Correct |
53 ms |
40780 KB |
Output is correct |
29 |
Correct |
100 ms |
79920 KB |
Output is correct |
30 |
Correct |
245 ms |
195612 KB |
Output is correct |
31 |
Correct |
258 ms |
195140 KB |
Output is correct |
32 |
Correct |
251 ms |
196160 KB |
Output is correct |
33 |
Correct |
251 ms |
196144 KB |
Output is correct |
34 |
Correct |
368 ms |
195740 KB |
Output is correct |
35 |
Correct |
296 ms |
195588 KB |
Output is correct |
36 |
Correct |
138 ms |
102212 KB |
Output is correct |
37 |
Correct |
165 ms |
123436 KB |
Output is correct |
38 |
Correct |
139 ms |
109700 KB |
Output is correct |
39 |
Correct |
30 ms |
22412 KB |
Output is correct |
40 |
Correct |
105 ms |
78020 KB |
Output is correct |
41 |
Correct |
6 ms |
4556 KB |
Output is correct |
42 |
Correct |
33 ms |
25164 KB |
Output is correct |
43 |
Correct |
64 ms |
49480 KB |
Output is correct |
44 |
Correct |
23 ms |
17740 KB |
Output is correct |
45 |
Correct |
259 ms |
195592 KB |
Output is correct |
46 |
Correct |
248 ms |
195492 KB |
Output is correct |
47 |
Correct |
251 ms |
196388 KB |
Output is correct |
48 |
Correct |
254 ms |
195560 KB |
Output is correct |
49 |
Correct |
304 ms |
195100 KB |
Output is correct |
50 |
Correct |
291 ms |
195232 KB |
Output is correct |
51 |
Correct |
207 ms |
163212 KB |
Output is correct |
52 |
Correct |
106 ms |
75036 KB |
Output is correct |
53 |
Correct |
34 ms |
23372 KB |
Output is correct |
54 |
Correct |
8 ms |
6156 KB |
Output is correct |
55 |
Correct |
5 ms |
3200 KB |
Output is correct |
56 |
Correct |
7 ms |
4700 KB |
Output is correct |
57 |
Correct |
101 ms |
75160 KB |
Output is correct |
58 |
Correct |
19 ms |
14224 KB |
Output is correct |
59 |
Correct |
171 ms |
132856 KB |
Output is correct |
60 |
Correct |
272 ms |
195396 KB |
Output is correct |
61 |
Correct |
247 ms |
195524 KB |
Output is correct |
62 |
Correct |
268 ms |
195416 KB |
Output is correct |
63 |
Correct |
273 ms |
195212 KB |
Output is correct |
64 |
Correct |
297 ms |
195584 KB |
Output is correct |
65 |
Correct |
342 ms |
195652 KB |
Output is correct |
66 |
Correct |
1 ms |
204 KB |
Output is correct |
67 |
Correct |
0 ms |
204 KB |
Output is correct |
68 |
Correct |
1 ms |
204 KB |
Output is correct |
69 |
Correct |
1 ms |
204 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
204 KB |
Output is correct |
73 |
Correct |
1 ms |
332 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
1 ms |
332 KB |
Output is correct |
76 |
Correct |
1 ms |
332 KB |
Output is correct |
77 |
Correct |
1 ms |
332 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
332 KB |
Output is correct |
80 |
Correct |
1 ms |
332 KB |
Output is correct |
81 |
Correct |
231 ms |
156820 KB |
Output is correct |
82 |
Correct |
65 ms |
36556 KB |
Output is correct |
83 |
Correct |
88 ms |
69664 KB |
Output is correct |
84 |
Correct |
48 ms |
37048 KB |
Output is correct |
85 |
Correct |
80 ms |
62296 KB |
Output is correct |
86 |
Correct |
90 ms |
53152 KB |
Output is correct |
87 |
Correct |
16 ms |
9264 KB |
Output is correct |
88 |
Correct |
8 ms |
5836 KB |
Output is correct |
89 |
Correct |
29 ms |
21908 KB |
Output is correct |
90 |
Correct |
294 ms |
195752 KB |
Output is correct |
91 |
Correct |
266 ms |
195520 KB |
Output is correct |
92 |
Correct |
275 ms |
195536 KB |
Output is correct |
93 |
Correct |
253 ms |
195564 KB |
Output is correct |
94 |
Correct |
269 ms |
195912 KB |
Output is correct |
95 |
Correct |
257 ms |
195860 KB |
Output is correct |
96 |
Correct |
251 ms |
195444 KB |
Output is correct |
97 |
Correct |
250 ms |
195612 KB |
Output is correct |
98 |
Correct |
305 ms |
195140 KB |
Output is correct |
99 |
Correct |
297 ms |
195816 KB |
Output is correct |
100 |
Correct |
308 ms |
194900 KB |
Output is correct |