Description
Solutions
Maximize Number of Produced Cars
πŸ‘©β€πŸŽ“ NEW GRAD

A car manufacturer has data about the production processes of N different cars (numbered from 0 to N-1) and wants to maximize the number of cars produced in the upcoming month. The manufacturing information is described by an array H, where H[K] denotes the number of hours required to produce the K-th car.

There are two assembly lines in the factory, the first of which works for X, and the second Y, hours in a month. Every car can be constructed using either one of these lines. Only one car at a time can be produced on each assembly line and it is not possible to switch lines after starting the car's production.

What is the maximum number of different cars that can be produced in the upcoming month?

Function Description

Write a function:

class Solution { public int solution(int[] H, int X, int Y); }

that, given an array H of N integers and two integers X and Y, returns the maximum number of different cars that can be produced in the upcoming month by assigning cars to assembly lines in an optimal way.

Example 1:

Input:  H = [1, 1, 3], X = 1, Y = 1
Output: 2
Explanation:
Only cars whose assembly time requires 1 hour can be constructed.

Example 2:

Input:  H = [6, 5, 5, 4, 3], X = 8, Y = 9
Output: 4
Explanation:
The cars that need 3 and 5 hours can be produced on the first assembly line while the second car that needs 5 hours and the car that needs 4 hours can be produced using the second line.

Example 3:

Input:  H = [6, 5, 2, 1, 8], X = 17, Y = 5
Output: 5
Explanation:
The car that needs 5 hours can be produced on the second line and the four other cars can be produced on the first line.

Example 4:

Input:  H = [5, 5, 4, 6], X = 8, Y = 8
Output: 2
Explanation:
Only one car can be produced on each line.
Constraints:
    • N is an integer within the range [1..1,000];
    • each element of array H is an integer within the range [1..1,000];
    • X and Y are integers within the range [1..500].
Thumbnail 0
Testcase

Result
Case 1

input:

output: