This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
map<int, int> hv;
int f(int col) {
if (!hv.count(col)) return 0;
return hv[col];
}
long long max_weights(int32_t n, int32_t m, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> w) {
int dp[n + 1][2][2], ans = 0;
for (int i = 0; i <= n; i++) for (int j = 0; j < 2; j++) for (int k = 0; k < 2; k++) dp[i][j][k] = 0;
for (int i = 0; i < m; i++) hv[(int) x[i]] = (int) w[i];
for (int i = 1; i < n; i++) {
dp[i][0][0] = max({dp[i-1][0][0], dp[i-1][1][0]});
dp[i][1][0] = max({dp[i-1][1][1] + f(i), dp[i-1][0][1] + f(i)});
dp[i][0][1] = max(dp[i-1][1][0], dp[i-1][0][0] + f(i-1));
dp[i][1][1] = max(dp[i-1][1][1], dp[i-1][0][1]);
ans = max(ans, max({dp[i][0][0], dp[i][0][1] + f(i+1), dp[i][1][1] + f(i+1), dp[i][1][0]}));
}
return ans;
}
#ifndef EVAL
int32_t main() {
int32_t N, M;
assert(2 == scanf("%d %d", &N, &M));
std::vector<int32_t> X(M), Y(M), W(M);
for (int32_t 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;
}
#endif
# | 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... |