# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628181 | Trisanu_Das | Catfish Farm (IOI22_fish) | C++17 | 0 ms | 0 KiB |
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;
#define ll long long int
#define MAXN 300064
ll pond[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) pond[X[i] + 1] = W[i];
for(int i = 2; i < N + 1; i++){
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + pond[i]); dp[i][1] = dp[i - 1][1];
if (i > 2) dp[i][1] = max({dp[i][1], dp[i - 2][0] + pond[i - 1], dp[i - 2][1] + pond[i - 1]});
else dp[i][1] = max(dp[i][1], pond[i - 1]);
}
ll ans = 0;
for (int i = 1; i < N + 1; i++) ans = max({ans, dp[i][0], dp[i][1]});
return (*max_element(Y.begin(), Y.end()) ? accumulate(W.begin(), W.end(), 0ll) : ans);