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>
#include <vector>
using namespace std;
const long long INF = 1e18;
const int MAXN = 1e5;
int n;
long long memo[MAXN];
bool cached[MAXN];
int a[MAXN];
long long dp(int i, bool check){
if(i >= n-1) return 0;
if(cached[i]) return memo[i];
long long res = -INF;
if(check){
long long act1 = dp(i+2, true) + a[i+1];
long long act2 = dp(i+1, false);
res = max({res, act1, act2});
} else {
long long act1 = dp(i+2, true) + a[i+1] + a[i-1];
long long act2 = dp(i+1, false);
res = max({res, act1, act2});
}
memo[i] = res;
cached[i] = true;
return res;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
n = N;
for(int i = 0; i < n; ++i) a[i] = 0;
for(int i = 0; i<M; ++i){
a[X[i]] = W[i];
}
return dp(0, true);
}
# | 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... |