cswork / OAOpen practice workspace

MathWorksOA #8

Alloy Production

Estimated MediumJudge-ready

Topics (AI-labelled)Binary Search

Each unit of alloy needs composition[i] units of metal i; you already have stock[i] and can buy more at a unit price of cost[i], with a budget of budget. Find the maximum number of units you can produce.

This site uses a standard input/output protocol.

Input

The first line contains n budget; the next three lines are composition, stock, and cost respectively. Constraints added by this site: 1≤n≤100000, 0≤budget≤10^9, 1≤composition[i],cost[i]≤10^9, 0≤stock[i]≤10^9.

Output

Output the maximum number of alloy units.

Example 1

Input:

2 3
1 2
0 1
1 1

Output:

1

Example 2

Input:

1 0
2
10
4

Output:

5

Example 3

Input:

2 5
1 1
0 0
2 3

Output:

1

Editorial

Loading solution…