#include <bits/stdc++.h>
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define pb push_back
#define eb emplace_back
#define id1 (id << 1)
#define id2 (id << 1) | 1
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vl vector<long long>
#define vll vector<pair<ll, ll>>
#define li pair<long long, int>
#define vil vector<pair<int, ll>>
#define db double
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F0R(i, a) FOR(i, 0, a - 1)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a - 1)
#define rep(a) F0R(_, a)
#define each(a, x) for (auto &a : x)
#define ALL(x) (x).begin(), (x).end()
#define pq priority_queue<li, vector<li>, greater<li>>
using namespace std;
vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int n = W.size();
int q = E.size();
vector<tuple<int, ll, ll>> vec;
F0R(i, n) {
vec.eb(W[i], A[i], B[i]);
}
sort(ALL(vec));
vector<ll> result;
for (int d_val : E) {
vl dp(n + 1, 1e18);
dp[0] = 0;
F0R(i, n) {
auto [w_i, a_i, b_i] = vec[i];
dp[i + 1] = min(dp[i + 1], dp[i] + a_i);
if (i >= 1) {
auto [w_prev, a_prev, b_prev] = vec[i - 1];
if (abs(w_i - w_prev) <= d_val) {
dp[i + 1] = min(dp[i + 1], (i >= 2 ? dp[i - 1] : 0) + b_prev + b_i);
}
}
if (i >= 2) {
auto [w_prev2, a_prev2, b_prev2] = vec[i - 2];
if (abs(w_i - w_prev2) <= d_val) {
dp[i + 1] = min(dp[i + 1], (i >= 3 ? dp[i - 2] : 0) + a_prev2 + b_i);
}
}
}
result.pb(dp[n]);
}
return result;
}
# | 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... |