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 <bits/stdc++.h>
// #include "fish.h"
#define tcT template<class T
#define fastio ios::sync_with_stdio(false);cin.tie(nullptr);
#define ln '\n'
#define nwln cout<<ln;
using namespace std;
tcT> using vr = vector<T>;
using ll = long long;
using vi = vr<int>;
using vl = vr<ll>;
using vvl = vr<vl>;
using vvvl = vr<vvl>;
#define eb emplace_back
#define fri(i,a,b) for(int i=(a); i<(b); ++i)
#define each(x, a) for(auto& x: a)
#define maxs(i, j) (i = max(i, j))
const int MX = (int) 3e5+3;
const int INF = 1001002003;
ll res;
vl val;
vvvl dp;
ll max_weights(int n, int m, vi x, vi y, vi w) {
dp.assign(n, vvl(2, vl(2, -INF))), res = 0;
val.assign(n, 0);
fri(i,0,m) val[x[i]] = w[i];
dp[0][0][0] = dp[0][1][0] = 0;
fri(i,0,n-1) {
maxs(dp[i+1][0][0], dp[i][0][0]);
maxs(dp[i+1][0][0], dp[i][0][1]);
// cout<<"dp["<<i+1<<"][0][0] = "<<dp[i+1][0][0]<<ln;
maxs(dp[i+1][1][0], dp[i][0][0] + val[i]);
maxs(dp[i+1][1][0], dp[i][0][1]);
// cout<<"dp["<<i+1<<"][1][0] = "<<dp[i+1][1][0]<<ln;
maxs(dp[i+1][0][1], dp[i][1][0] + val[i+1]);
maxs(dp[i+1][0][1], dp[i][1][1] + val[i+1]);
// cout<<"dp["<<i+1<<"][0][1] = "<<dp[i+1][0][1]<<ln;
maxs(dp[i+1][1][1], dp[i][1][1]);
maxs(dp[i+1][1][1], dp[i][1][0]);
// cout<<"dp["<<i+1<<"][1][1] = "<<dp[i+1][1][1]<<ln;
}
fri(i,0,2) {
fri(j,0,2) maxs(res, dp[n-1][i][j]);
}
return res;
}
# | 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... |