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 <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
int n, m;
vector<int> x, y, w;
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
n = N; m = M; x = X; y = Y; w = W;
vector<ll> a(n);
for (int i = 0; i < m; i++) {
a[x[i]] = w[i];
}
vector<ll> dp(n);
dp[1] = w[0];
for (int i = 2; i < n; i++) {
dp[i] = w[i-1];
for (int j = i-1; j >= 0 && j >= i-5; j--) {
ll val = dp[j];
if (i-j > 1) val += w[i-1];
if (i-j > 2) val += w[j+1];
dp[i] = max(dp[i], val);
}
}
ll res = dp[n-1];
for (int i = n-2; i >= n-5 && i >= 0; i--) {
res = max(res, dp[i] + w[i+1]);
}
return res;
}
#ifdef TEST
#include "grader.cpp"
#endif
# | 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... |