선수 관계 트리에서 예산을 써서 각 기술의 최대 레벨 한도 안에서 레벨을 올리고, 레벨과 중요도의 곱의 합을 최대로 만든다.
어려움8트리동적 계획법그리디아직 제출이 없습니다시간 제한8초메모리 제한512 MBA countless number of skills are required to be an excellent programmer. Different skills have different importance degrees, and the total programming competence is measured by the sum of products of levels and importance degrees of his/her skills.
In this summer season, you are planning to attend a summer programming school. The school offers courses for many of such skills. Attending a course for a skill, your level of the skill will be improved in proportion to the tuition paid, one level per one yen of tuition, however, each skill has its upper limit of the level and spending more money will never improve the skill level further. Skills are not independent: For taking a course for a skill, except for the most basic course, you have to have at least a certain level of its prerequisite skill.
You want to realize the highest possible programming competence measure within your limited budget for tuition fees.
The input consists of no more than 100 datasets, each in the following format.
n k
h1 ... hn
s1 ... sn
p2 ... pn
l2 ... ln
The end of the input is indicated by a line containing two zeros.
For each dataset, output a single line containing one integer, which is the highest programming competence measure achievable, that is, the maximum sum of the products of levels and importance degrees of the skills, within the given tuition budget, starting with level zero for all the skills. You do not have to use up all the budget.