This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 dp [N][N][2];
int k, n, m, a, b;
int felicidade_evento [N];
int dia_evento [N];
int tarefas [N];
int solve (int p, int task, bool is_skip) {
if (task >= m) {
return 0;
}
if (p >= n) {
if (!is_skip) {
return ( a + (m - task) * b);
} else {
return ( (m - task) * b );
}
}
int &res = dp[p][task][is_skip];
if (~res) return res;
res = -1e9;
if (tarefas[task] == dia_evento[p]) {
res = max (res, felicidade_evento[tarefas[task]] + solve (p + 1, task + 1, false));
} else {
if (is_skip == false) {
res = max (res, a + b + solve (p, task + 1, true));
res = max (res, a + b + solve (p + 1, task, true));
} else {
res = max (res, b + solve (p, task + 1, true));
res = max (res, a + b + solve (p + 1, task, true));
}
}
return res;
}
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];
memset (dp, -1, sizeof(dp));
int mn = -1e9;
for (int i = 0; i < n; i++) {
mn = max (mn, solve (i, 0, false));
}
cout << mn << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |