1031. Railway Tickets @ Timus Online Judge
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
vector<unsigned long long> l(4), c(4), sta;
int n,s,e;
vector<unsigned long long> f(10010, INT_MAX);
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
//freopen(".in", "r", stdin);
for (int i = 1; i <= 3; i++)
cin >> l[i];
for (int i = 1; i <= 3; i++)
cin >> c[i];
cin >> n >> s >> e;
if (s > e)
swap(s, e);
sta.push_back(0);
for (int i = 1; i < n; i++)
{
int a;
cin >> a;
sta.push_back(a);
}
s--; e--;
f[s] = 0;
for (int i = s; i <= e; i++)
{
for (int j = i - 1; j >= s && sta[i] - sta[j] <= l[3]; j--)
{
if (sta[i] - sta[j] <= l[1])
f[i] = min(f[i], f[j] + c[1]);
else
if (sta[i] - sta[j] <= l[2])
f[i] = min(f[i], f[j] + c[2]);
else
f[i] = min(f[i], f[j] + c[3]);
}
}
cout << f[e] << endl;
return 0;
}