#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Fish = array<int, 3>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
const double eps = 1e-9;
void setIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int64_t max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
bool even = true;
bool sub2 = true;
bool sub3 = true;
for(int i=0; i<m; i++) {
if(x[i] % 2 == 1) even = false;
if(x[i] > 1) sub2 = false;
if(y[i] > 0) sub3 = false;
}
if(even) {
ll ans = 0;
for(int &x : w) ans += x;
return ans;
}
if(sub2) {
ll ans = 0;
ll prefix[n][2];
memset(prefix, 0, sizeof(prefix));
for(int i=0; i<m; i++)
prefix[y[i]][x[i]] += w[i];
for(int i=1; i<n; i++) {
prefix[i][0] += prefix[i-1][0];
prefix[i][1] += prefix[i-1][1];
}
if(n == 2) return max(prefix[n-1][0], prefix[n-1][1]);
for(int i=0; i<n; i++) {
ll res = 0;
res += prefix[i][0];
res += prefix[n-1][1];
res -= prefix[i][1];
ans = max(ans, res);
ll res2 = 0;
ans = max(ans, res2);
}
return max({ ans, prefix[n-1][0], prefix[n-1][1] });
}
if(sub3) {
vector<int> v(n, 0);
vector<ll> dp(n, 0);
vector<ll> mx(n, 0);
for(int i=0; i<m; i++)
v[x[i]] = w[i];
dp[0] = (n > 1 ? v[1] : 0);
mx[0] = dp[0];
for(int i=1; i<n; i++) {
ll res1 = dp[i-1];
if(i < n-1) res1 += v[i+1];
ll res2 = (i > 1 ? dp[i-2] : 0);
if(i < n-1) res2 += v[i+1];
ll res3 = (i > 2 ? mx[i-3] : 0);
res3 += v[i-1];
if(i < n-1) res3 += v[i+1];
dp[i] = max(dp[i], res1);
dp[i] = max(dp[i], res2);
dp[i] = max(dp[i], res3);
mx[i] = max(mx[i-1], dp[i]);
}
return *max_element(all(dp));
}
return 0;
}
int32_t main() {
setIO();
int n, m;
cin >> n >> m;
vector<int> x(m), y(m), w(m);
for(int i=0; i<m; i++)
cin >> x[i] >> y[i] >> w[i];
cout << max_weights(n, m, x, y, w) << '\n';
return 0;
}
Compilation message
/usr/bin/ld: /tmp/ccBC9fhT.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccn9gPiT.o:fish.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status