PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000466. Tối ưu năng lực sản xuất (Sensor Optimization Dilemma 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tối ưu năng lực sản xuất (Sensor Optimization Dilemma 2)

Sensor Optimization Dilemma 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A production line has NN stages. At stage ii, a unit of type S provides daily capacity AiA_i at cost PiP_i, and type T provides BiB_i at cost QiQ_i. Any nonnegative integer number of units may be bought. The line capacity is the minimum of the stage capacities. Maximize it without exceeding budget XX.

Input

The first line contains N,XN,X. The next NN lines contain Ai,Pi,Bi,QiA_i,P_i,B_i,Q_i, respectively.

Output

Print the maximum capacity as an integer.

Subtasks

  • Subtask 1 (20 points): 1≤N≤51\le N\le 5; 1≤X≤1001\le X\le 100; 1≤Ai,Bi≤1001\le A_i,B_i\le100; 1≤Pi,Qi≤1071\le P_i,Q_i\le10^7 (1≤i≤N1\le i\le N).
  • Subtask 2 (30 points): 1≤N≤301\le N\le 30; 1≤X≤100000001\le X\le 10000000; 1≤Ai,Bi≤1001\le A_i,B_i\le100; 1≤Pi,Qi≤1071\le P_i,Q_i\le10^7 (1≤i≤N1\le i\le N).
  • Subtask 3 (50 points): 1≤N≤1001\le N\le 100; 1≤X≤100000001\le X\le 10000000; 1≤Ai,Bi≤1001\le A_i,B_i\le100; 1≤Pi,Qi≤1071\le P_i,Q_i\le10^7 (1≤i≤N1\le i\le N).

Examples

Example 1

Input

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

Output

4

Explanation

Buy two S units, one S plus one T, and two T units, respectively. Cost is 22 and every capacity is 4. Capacity 5 needs at least 27.

Example 2

Input

1 10000000
100 1 100 1

Output

1000000000

Explanation

Buy 10710^7 machines at unit cost 1 and capacity 100.

Example 3

Input

1 1
1 10000000 1 10000000

Output

0

Explanation

No machine is affordable.

Example 4

Input

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

Output

894742

Explanation

Capacity 894742 is affordable, but increasing it by one is not.