291 传统题

[ABC374E] 流水线产能上限 (Sensor Optimization Dilemma 2)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
0/ 0
难度
4

[ABC374E] 流水线产能上限 (Sensor Optimization Dilemma 2)

Problem Statement

The manufacturing of a certain product requires NN processes numbered 1,2,…,N1,2,\dots,N.

For each process ii, there are two types of machines SiS_i and TiT_i available for purchase to handle it.

  • Machine SiS_i: Can process AiA_i products per day per unit, and costs PiP_i yen per unit.

  • Machine TiT_i: Can process BiB_i products per day per unit, and costs QiQ_i yen per unit.

You can purchase any number of each machine, possibly zero.

Suppose that process ii can handle WiW_i products per day as a result of introducing machines.

Here, we define the production capacity as the minimum of WW, that is, min⁡i=1NWi\displaystyle \min^{N}_{i=1} W_i.

Given a total budget of XX yen, find the maximum achievable production capacity.

Input

The input is given from Standard Input in the following format:

$N$ $X$
$A_1$ $P_1$ $B_1$ $Q_1$
$A_2$ $P_2$ $B_2$ $Q_2$
$\vdots$
$A_N$ $P_N$ $B_N$ $Q_N$

Output

Print the answer as an integer.

Example

3 22
2 5 3 6
1 1 3 3
1 3 2 4
4

Note

  • Constraints:

  • All input values are integers.

  • 1≤N≤1001 \le N \le 100

  • 1≤Ai,Bi≤1001 \le A_i,B_i \le 100

  • 1≤Pi,Qi,X≤1071 \le P_i,Q_i,X \le 10^7

  • Source: ABC374E