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"
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define trav(a, x) for (auto &a : x)
using namespace std;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
ll m = M;
ll ans = 0;
if (count(all(Y), 0) == M) {
vector<pair<ll, ll>> tmp(m);
rep(i, 0, m) {
tmp[i] = {X[i], W[i]};
}
sort(all(tmp));
vector<int> w(m);
rep(i, 0, m) w[i] = tmp[i].second;
ll dp[m][2][2]; // [pos][include cur][pier]
memset(dp, 0, sizeof(dp));
rep(i, 1, m) {
dp[i][1][1] = 0; // cant include cur and have pier on cur;
dp[i][1][0] = max(dp[i-1][0][1], dp[i-1][1][1]) + w[i];
dp[i][0][0] = max(dp[i-1][0][0], dp[i-1][1][0]);
dp[i][0][1] = max({dp[i-1][0][0] + w[i-1], dp[i-1][0][1], dp[i-1][1][0], dp[i-1][1][1]});
}
rep(i, 0, 2) rep(j, 0, 2) {
ans = max(dp[m-1][i][j], ans);
}
}
else {
rep(i, 0, m) {
ans += W[i];
}
}
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... |