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 "fish.h"
#include <vector>
using namespace std;
using ll = long long;
const int N_MAX = 100005;
ll v[N_MAX];
ll dp[N_MAX];
bool got[N_MAX];
ll f(int i) {
if (i == 0) return 0;
if (got[i]) return dp[i];
ll ans = f(i-1);
if (i == 1) {
ans = max(v[0], v[1]);
} else if (i == 2) {
ans = max(ans, v[0] + v[2]);
}
if (i >= 2) {
ans = max(ans, v[i-1] + f(i-2));
}
if (i >= 3) {
ans = max(ans, f(i-3) + v[i] + v[i-2]);
}
if (i >= 4) {
ans = max(ans, f(i-4) + v[i] + v[i-3]);
}
got[i] = true;
return dp[i] = ans;
}
ll max_weights(
int N, int M, vector<int> X, vector<int> Y, vector<int> W
) {
for (int i = 0; i < M; i++)
v[X[i]] = W[i];
return f(N-1);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |