# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785100 | khshg | 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>
using namespace std;
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
long long ans = 0;
vector<int> c(N + 1);
for(int i = 0; i < M; ++i) {
c[X[i]] = W[i];
}
vector<array<long long, 2>> dp(N + 1);
dp[0][0] = 0;
dp[0][1] = c[1];
ans = c[1];
for(int i = 1; i < N; ++i) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = dp[i - 1][1] - c[i];
dp[i][1] = max(dp[i][1], (i - 2 < 0 ? 0 : dp[i - 2][0]) + c[i - 1]);
dp[i][1] = max(dp[i][1], (i - 2 < 0 ? 0 : dp[i - 2][1]);
dp[i][1] += c[i + 1];
ans = max(dp[i][0], dp[i][1]);
}
return ans;
}