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>
using namespace std;
typedef long long ll;
int N, M;
vector<int> X, Y, W;
vector<ll> c, dp;
ll get_score(int l, int r)
{
if (l < 0) return 0;
if (l == r - 1)
return dp[l] - c[r] - c[l];
if (l == r - 2)
return dp[l] - c[l+1];
return dp[l];
}
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_;
c = vector<ll>(N+1);
dp = vector<ll>(N);
for (int i = 0; i < N; i++)
c[X[i]] = W[i];
dp[0] = c[1];
for (int i = 1; i < N; i++)
{
dp[i] = c[i-1] + c[i+1] + max({get_score(i-3, i), get_score(i-2, i), get_score(i-1, i)});
}
ll mx = 0;
for (int i = 0; i < N; i++)
mx = max(mx, dp[i]);
return mx;
}
# | 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... |