#include <bits/stdc++.h>
#define task "TEST"
#define task2 "A"
#define pl pair<ll, ll>
#define VI vector<int>
#define VL vector<ll>
#define pf push_front
#define pb push_back
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b, c) for (int i=a; i<=b; i+=c)
#define FORE(i, a, b, c) for (int i=a; i>=b; i+=c)
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int Mod = 1e9+7;
const int maxn = 2e5;
const ll Inf = 1e16;
ll n, q;
struct Object {
ll w, a, b;
bool operator < (Object other) {
return w < other.w;
};
};
Object O[maxn+1]; ll dp[maxn+1];
VL calculate_costs(VI W, VI A, VI B, VI E) {
q = E.size(); n = W.size(); VL res;
ll sum = 2*n;
FOR(i, 0, n-1, 1) O[i+1] = {W[i], A[i], B[i]};
sort(O + 1, O + n + 1);
FOR(i, 0, q-1, 1) {
memset(dp, 0, sizeof(dp)); dp[1] = O[1].a;
FOR(j, 2, n, 1) {
if (O[j].w - O[j-1].w <= E[i])
dp[j] = min(dp[j-1] + O[j].a, dp[j-2] + O[j-1].b + O[j].b);
else dp[j] = dp[j-1] + O[j].a;
}
res.pb(dp[n]);
}
return res;
}
/*void Read()
{
}
void Solve()
{
for (auto p : calculate_costs({15, 12, 2, 10, 21}, {2, 2, 2, 2, 2}, {1, 2, 2, 1, 2}, {5, 9, 1})) cout << p << '\n';
}
int main()
{
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
for (t=1; t--;)
{
Read(); Solve();
}
}*/