/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 2e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define ForE(i, a, b) for(int i = (a); i <= (b); ++i)
int K, n, m, A, B;
int hpn[1005], events[5005], mission[5005];
int dp[5005][5005][2], nxt[5005][5005];
int cal(int val) {
if (val == 0) return 0;
return A + val * B;
}
void chkmax(int &val, int nval) {
val = (val < nval ? nval : val);
}
void solve() {
cin >> K >> n >> m >> A >> B;
for (int i = 1; i <= K; ++i) cin >> hpn[i];
for (int i = 1; i <= n; ++i) cin >> events[i];
for (int i = 1; i <= m; ++i) cin >> mission[i];
memset(nxt[m + 1], -1, sizeof nxt[0]);
for (int i = m; i >= 1; --i) {
for (int j = 1; j <= K; ++j) nxt[i][j] = nxt[i + 1][j];
nxt[i][mission[i]] = i;
}
ForE(day, 0, n) ForE(i, 0, m) For(cont, 0, 2) {
dp[day][i][cont] = INT_MIN;
}
ForE(day, 0, n) dp[day][0][0] = 0;
For(day, 0, n) For(i, 0, m) For(cont, 0, 2) if (dp[day][i][cont] != INT_MIN) {
int val = dp[day][i][cont];
// cout << day << " " << i << " " << cont << " " << val << " " << i + 1 << " " << events[day + 1] << endl;
if (nxt[i + 1][events[day + 1]] != -1) {
int ni = nxt[i + 1][events[day + 1]];
// cout << ni << " " << val + hpn[events[day + 1]] << " " << cal(ni - i - 1) << endl;
chkmax(dp[day + 1][ni][1], val + hpn[events[day + 1]] + cal(ni - i - 1));
}
chkmax(dp[day + 1][i][0], val + (cont ? A + B : B));
}
int res = INT_MIN;
for (int day = 1; day <= n; ++day) for (int i = 0; i <= m; ++i) for (int cont = 0; cont < 2; ++cont) if (dp[day][i][cont] != INT_MIN) {
// cout << day << " " << i << " " << cont << " " << dp[day][i][cont] << endl;
chkmax(res, dp[day][i][cont] + cal(m - i));
}
cout << res << endl;
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
cout << "Check array size pls sir" << endl;
#endif
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
13 ms |
57968 KB |
Output is correct |
3 |
Correct |
2 ms |
14680 KB |
Output is correct |
4 |
Correct |
4 ms |
39260 KB |
Output is correct |
5 |
Correct |
2 ms |
18780 KB |
Output is correct |
6 |
Correct |
6 ms |
39260 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
24924 KB |
Output is correct |
9 |
Correct |
8 ms |
45660 KB |
Output is correct |
10 |
Correct |
13 ms |
62040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
20824 KB |
Output is correct |
2 |
Correct |
1 ms |
10588 KB |
Output is correct |
3 |
Correct |
5 ms |
31068 KB |
Output is correct |
4 |
Correct |
1 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
18780 KB |
Output is correct |
6 |
Correct |
8 ms |
43496 KB |
Output is correct |
7 |
Correct |
7 ms |
41564 KB |
Output is correct |
8 |
Correct |
10 ms |
53852 KB |
Output is correct |
9 |
Correct |
3 ms |
18780 KB |
Output is correct |
10 |
Correct |
13 ms |
62088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
125528 KB |
Output is correct |
2 |
Correct |
18 ms |
109144 KB |
Output is correct |
3 |
Correct |
93 ms |
195420 KB |
Output is correct |
4 |
Runtime error |
51 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
125528 KB |
Output is correct |
2 |
Correct |
18 ms |
109144 KB |
Output is correct |
3 |
Correct |
93 ms |
195420 KB |
Output is correct |
4 |
Runtime error |
51 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
125528 KB |
Output is correct |
2 |
Correct |
18 ms |
109144 KB |
Output is correct |
3 |
Correct |
93 ms |
195420 KB |
Output is correct |
4 |
Runtime error |
51 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4568 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
13 ms |
57968 KB |
Output is correct |
3 |
Correct |
2 ms |
14680 KB |
Output is correct |
4 |
Correct |
4 ms |
39260 KB |
Output is correct |
5 |
Correct |
2 ms |
18780 KB |
Output is correct |
6 |
Correct |
6 ms |
39260 KB |
Output is correct |
7 |
Correct |
2 ms |
12636 KB |
Output is correct |
8 |
Correct |
4 ms |
24924 KB |
Output is correct |
9 |
Correct |
8 ms |
45660 KB |
Output is correct |
10 |
Correct |
13 ms |
62040 KB |
Output is correct |
11 |
Correct |
3 ms |
20824 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
5 ms |
31068 KB |
Output is correct |
14 |
Correct |
1 ms |
10588 KB |
Output is correct |
15 |
Correct |
3 ms |
18780 KB |
Output is correct |
16 |
Correct |
8 ms |
43496 KB |
Output is correct |
17 |
Correct |
7 ms |
41564 KB |
Output is correct |
18 |
Correct |
10 ms |
53852 KB |
Output is correct |
19 |
Correct |
3 ms |
18780 KB |
Output is correct |
20 |
Correct |
13 ms |
62088 KB |
Output is correct |
21 |
Correct |
35 ms |
125528 KB |
Output is correct |
22 |
Correct |
18 ms |
109144 KB |
Output is correct |
23 |
Correct |
93 ms |
195420 KB |
Output is correct |
24 |
Runtime error |
51 ms |
262144 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |