// #include "fish.h"
#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 dp[n+2][4][4]{};
vector<pair<int,int>>hv[n+2];
vector<int>to[n+2];
for(int i = 0; i < m; i++){
hv[x[i]+2].push_back({y[i]+1,w[i]});
to[x[i]+2].push_back(y[i]);
}
for(int i = 0; i <= n; i++){
to[i].push_back(0);
if(i > 1){
to[i].push_back(n+2);
}
sort(to[i].begin(), to[i].end());
}
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
dp[0][i][j] = -1e18;
dp[1][i][j] = -1e18;
}
}
dp[0][0][0] = 0;
dp[1][0][0] = 0;
long long ans = 0;
for(int i = 2; i <= n+1; i++){
int sz = 0;
for(int j = 0; j < to[i-2].size(); j++){
for(int k = 0; k < to[i-1].size(); k++){
for(int v = 0; v < to[i].size(); v++){
long long now = dp[i-1][k][j];
for(auto nodes : hv[i-1]){
if(nodes.first > max(to[i-2][j],to[i-1][k])){
if(nodes.first < to[i][v]){
now += nodes.second;
}
}
}
for(auto nodes : hv[i]){
if(nodes.first > to[i][v]){
if(nodes.first < to[i-1][k]){
now += nodes.second;
}
}
}
dp[i][v][k] = max(dp[i][v][k],now);
ans = max(ans,now);
}
}
}
}
return ans;
}
int main(){
cout << max_weights(5, 4, {0, 1, 4, 3}, {2, 1, 4, 3}, {5, 2, 1, 3}) << '\n';
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:33:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int j = 0; j < to[i-2].size(); j++){
| ~~^~~~~~~~~~~~~~~~
fish.cpp:34:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int k = 0; k < to[i-1].size(); k++){
| ~~^~~~~~~~~~~~~~~~
fish.cpp:35:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int v = 0; v < to[i].size(); v++){
| ~~^~~~~~~~~~~~~~
fish.cpp:32:13: warning: unused variable 'sz' [-Wunused-variable]
32 | int sz = 0;
| ^~
/usr/bin/ld: /tmp/ccPwaINk.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccRsKv7i.o:fish.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status