#include <bits/stdc++.h>
//#include "fish.h"
using namespace std;
#pragma GCC optimize("O3")
#define endl '\n'
#define db double
#define ll long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;
const int Max = 1e6 + 7, Inf = 1e9 + 7;
void print(bool x) { cout << (x ? "YES" : "NO") << endl; }
string tostring (__int128 x)
{
string ans = "";
while(x > 0)
{
ans += (x % 10 + '0');
x /= 10;
}
reverse(all(ans));
return ans;
}
long long max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W)
{
//vector <vector<pair<int, int>>> v(n + 1, vector <pair<int, int>> ());
vector <vector<ll>> v(n, vector <ll> (n+1, 0));
map <int, map <int, int>> mp;
for(int i = 0; i < m; i++){
v[X[i]][Y[i]+1] = W[i];
//v[X[i]].push_back({ Y[i], W[i] });
}
vector <vector<ll>> dp1(n + 1, vector <ll> (n + 1, 0)),
dp2(n + 1, vector <ll> (n + 1, 0));
ll ans = 0;
for(int i = 0; i < n; i++)
{
for(int j = 1; j <= n; j++){
v[i][j] += v[i][j-1];
}
}
auto C = [&] (int i, int j, int k) -> ll
{
ll ans = 0;
if(i >= 0 && i < n) {
ans = ans + max(0LL, v[i][j] - v[i][k]);
}
return ans;
};
for(int i = 0; i < n; i++)
{
for(int j = 0; j <= n; j++)
{
for(int k = 0; k <= n; k++){
dp1[i][j] = max(dp1[i][j], (i > 1 ? dp2[i-2][k] : 0LL) + C(i-1, j, k) + C(i+1, j, 0));
}
for(int k = 0; k <= j; k++){
dp1[i][j] = max(dp1[i][j], (i != 0 ? dp1[i-1][k] : 0) + C(i-1, j, k) + C(i+1, j, 0) - C(i, k, 0));
}
for(int k = j; k <= n; k++){
dp2[i][j] = max(dp2[i][j], (i != 0 ? dp1[i-1][k] : 0) - C(i, j, 0) + C(i+1, j, 0));
dp2[i][j] = max(dp2[i][j], (i != 0 ? dp2[i-1][k] : 0) - C(i, j, 0) + C(i+1, j, 0));
}
ans = max(ans, max(dp1[i][j], dp2[i][j]));
}
}
return ans;
}
int main() {
int N, M;
assert(2 == scanf("%d %d", &N, &M));
std::vector<int> X(M), Y(M), W(M);
for (int i = 0; i < M; ++i) {
assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i]));
}
long long result = max_weights(N, M, X, Y, W);
printf("%lld\n", result);
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccBtHLAT.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccRmkP7S.o:fish.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status