# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
925186 | 2024-02-11T00:18:52 Z | IS_Rushdi | Catfish Farm (IOI22_fish) | C++17 | 0 ms | 0 KB |
#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 pre[n+2][n+2]{}; long long dp[n+1][n+1]{}; for(int i = 0; i < m; i++) x[i]++,y[i]++; for(int i = 0; i < m; i++) pre[x[i]][y[i]] += w[i]; for(int i = 1; i <= n; i++){ for(int j = n; j >= 0; j--){ pre[i][j] += pre[i][j+1]; } } for(int i = 1; i <= n; i++) dp[0][i] = -2e18ll; long long ans = 0; for(int i = 1; i <= n; i++){ for(int j = 0; j <= n; j++){ long long add = dp[i-1][j] + pre[i][j+1]; for(int k = 0; k <= n; k++){ long long add2 = pre[i-1][k+1]; dp[i][k] = max(dp[i][k],add + add2); ans = max(ans,dp[i][k]); } } } return ans; }