#abc374e. E - Sensor Optimization Dilemma 2

E - Sensor Optimization Dilemma 2

Score : 475475 points

问题陈述

制造某种产品需要NN个流程,编号为1,2,,N1,2,\dots,N

对于每个流程ii,有两种类型的机器SiS_iTiT_i可供购买以处理它。

  • 机器SiS_i:每台每天可以处理AiA_i个产品,每台成本为PiP_i日元。
  • 机器TiT_i:每台每天可以处理BiB_i个产品,每台成本为QiQ_i日元。

你可以购买每种机器的任意数量,可能是零。

假设流程ii由于引入机器,每天可以处理WiW_i个产品。 在这里,我们定义生产能力为WW的最小值,即mini=1NWi\displaystyle \min^{N}_{i=1} W_i

给定总预算为XX日元,找出可实现的最大生产能力。

以上为大语言模型 kimi 翻译,仅供参考。

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, mini=1NWi\displaystyle \min^{N}_{i=1} W_i.

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

Constraints

  • All input values are integers.
  • 1N1001 \le N \le 100
  • 1Ai,Bi1001 \le A_i,B_i \le 100
  • 1Pi,Qi,X1071 \le P_i,Q_i,X \le 10^7

Input

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

NN XX

A1A_1 P1P_1 B1B_1 Q1Q_1

A2A_2 P2P_2 B2B_2 Q2Q_2

\vdots

ANA_N PNP_N BNB_N QNQ_N

Output

Print the answer as an integer.

Sample Input 1

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

Sample Output 1

4

For example, by introducing machines as follows, we can achieve a production capacity of 44, which is the maximum possible.

  • For process 11, introduce 22 units of machine S1S_1.
    • This allows processing 44 products per day and costs a total of 1010 yen.
  • For process 22, introduce 11 unit of machine S2S_2.
    • This allows processing 11 product per day and costs a total of 11 yen.
  • For process 22, introduce 11 unit of machine T2T_2.
    • This allows processing 33 products per day and costs a total of 33 yen.
  • For process 33, introduce 22 units of machine T3T_3.
    • This allows processing 44 products per day and costs a total of 88 yen.

Sample Input 2

1 10000000
100 1 100 1

Sample Output 2

1000000000

Sample Input 3

1 1
1 10000000 1 10000000

Sample Output 3

0

There may be cases where a positive production capacity cannot be achieved.

Sample Input 4

10 7654321
8 6 9 1
5 6 4 3
2 4 7 9
7 8 9 1
7 9 1 6
4 8 9 1
2 2 8 9
1 6 2 6
4 2 3 4
6 6 5 2

Sample Output 4

894742