Under construction

Still being built. Things may change

Exam

Time limit1sMemory limit1024 MB

Summary
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 NN problems, and Joonatan has TT minutes to solve them. The exam starts at time 00 and ends at time TT. He may leave the exam at any integer time from 00 to TT.

There are two kinds of problems: easy and hard. An easy problem takes exactly AA minutes to solve, and a hard problem takes exactly BB minutes. If he starts an easy problem at time xx, he finishes it at time x+Ax + A. If he starts a hard problem at time yy, he finishes it at time y+By + B. 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 ii also has a time tit_i, from which that problem becomes mandatory. If Joonatan leaves the exam at time ss and some problem ii with ti≤st_i \le s is not solved, he gets 00 points for the whole exam. Otherwise he gets one point for each solved problem. When he leaves at time ss, 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: NN (2≤N≤5⋅1052 \le N \le 5 \cdot 10^5), TT (1≤T≤1091 \le T \le 10^9), AA, and BB (1≤A<B≤1091 \le A < B \le 10^9).

The second line contains NN integers. The ii-th number is 00 if problem ii is easy, and 11 if it is hard.

The third line contains NN integers tit_i (0≤ti≤T0 \le t_i \le T). The ii-th number is the time at which problem ii becomes mandatory.

Output

Print one integer: the maximum number of points Joonatan can get on this exam.

Examples3

  1. Example 1

    Input
    2 5 2 3
    1 0
    3 2
    
    Expected output
    2
    
  2. Example 2

    Input
    6 20 3 6
    0 1 0 0 1 0
    20 11 3 20 16 17
    
    Expected output
    4
    
  3. Example 3

    Input
    6 20 2 5
    1 1 0 1 0 0
    0 8 2 9 11 6
    
    Expected output
    0