Exam
Time limit1sMemory limit1024 MB
Given N easy or hard problems with mandatory times t_i, find the leave time and solved set that maximize points without leaving any mandatory problem unsolved.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
Joonatan has to take a math exam and wants to score as many points as possible. He studied the rules carefully to find out how to pass the exam.
The exam has problems, and Joonatan has minutes to solve them. The exam starts at time and ends at time . He may leave the exam at any integer time from to .
There are two kinds of problems: easy and hard. An easy problem takes exactly minutes to solve, and a hard problem takes exactly minutes. If he starts an easy problem at time , he finishes it at time . If he starts a hard problem at time , he finishes it at time . For each problem, it is known whether it is easy or hard. Solving a hard problem always takes more time than solving an easy one. Joonatan can solve only one problem at a time.
Each problem also has a time , from which that problem becomes mandatory. If Joonatan leaves the exam at time and some problem with is not solved, he gets points for the whole exam. Otherwise he gets one point for each solved problem. When he leaves at time , he may have solved both mandatory problems and problems that are not yet mandatory.
Find the maximum number of points Joonatan can get on this exam.
Input
The first line contains four integers separated by spaces: (), (), , and ().
The second line contains integers. The -th number is if problem is easy, and if it is hard.
The third line contains integers (). The -th number is the time at which problem becomes mandatory.
Output
Print one integer: the maximum number of points Joonatan can get on this exam.