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 <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 300064;
ll a[MAXN], dp[MAXN][2];
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
for (int i = 0; i < M; ++i)
a[X[i] + 1] = W[i];
for (int i = 2; i <= N; ++i) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + a[i]);
dp[i][1] = dp[i - 1][1];
if (i > 2) dp[i][1] = max({ dp[i][1], dp[i - 2][0] + a[i - 1], dp[i - 2][1] + a[i - 1] });
else dp[i][1] = max(dp[i][1], a[i - 1]);
}
ll ans = 0;
for (int i = 1; i <= N; ++i)
ans = max({ ans, dp[i][0], dp[i][1] });
return (*max_element(Y.begin(), Y.end()) ? accumulate(W.begin(), W.end(), 0ll) : ans);
}
# | 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... |