# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628107 | 2022-08-13T05:18:23 Z | TheQuantiX | Catfish Farm (IOI22_fish) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n, m, x, y, k; void solve() { cin >> n >> m; vector<ll> v(n); for (int i = 0; i < m; i++) { cin >> x >> y >> k; v[x] += k; } vector<ll> dp(n + 1); for (int i = 1; i <= n; i++) { dp[i] = v[i - 1]; if (i >= 2) { dp[i] = max(dp[i], dp[i - 2] + v[i - 1]); } if (i >= 3) { dp[i] = max(dp[i], dp[i - 3] + v[i - 1]); } // cout << dp[i] << '\n'; } cout << *max_element(dp.begin(), dp.end()) << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }