#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
ll mat[n + 5][n + 5] = {}, pref[n + 5][n + 5] = {};
for (int i = 0; i < m; i ++)
mat[x[i] + 1][y[i] + 1] = w[i];
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= n; j ++)
pref[i][j] = pref[i][j - 1] + mat[i][j];
ll dp[n + 1][n + 1] = {};
for (int k = 1; k <= n; k ++)
dp[1][k] = pref[2][k];
for (int i = 2; i <= n; i ++){
for (int k = 0; k <= n; k ++){
for (int pk = 0; pk <= n; pk ++){
if (k >= pk) dp[i][k] = pref[i + 1][k] + pref[i - 1][k] - pref[i - 1][pk] + dp[i - 1][pk];
else dp[i][k] = pref[i + 1][k] + dp[i - 1][pk] - pref[i][k];
}
}
}
ll ans = 0;
for (int k = 0; k <= n; k ++)
ans = max(ans, dp[n][k]);
return ans;
}
# | 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... |