Help ramu challange fundamental by java

Ramu often uses public transport. The transport in the city is of two types: cabs and rickshaws. The city has n rickshaws and m cabs, the rickshaws are numbered by integers from 1 to n, the cabs are numbered by integers from 1 to m.

Public transport is not free. There are 4 types of tickets:

A ticket for one ride on some rickshaw or cab. It costs c1 ruppees;
A ticket for an unlimited number of rides on some rickshaw or on some cab. It costs c2 ruppees;
A ticket for an unlimited number of rides on all rickshaws or all cabs. It costs c3 ruppees;
A ticket for an unlimited number of rides on all rickshaws and cabs. It costs c4 ruppees.

Ramu knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of ruppees he will have to spend on the tickets.

Input Format
Each Test case has 4 lines which are as follows:

The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.
The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rickshaws and cabs Ramu is going to use.
The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Ramu is going to use the rickshaw number i.
The fourth line contains m integers bi (0 ≤ bi ≤ 1000) — the number of times Ramu is going to use the cab number i.

@chaman_31599,

You are required to find cost of each of the cases:

when he pay c1 for each ride he took in a rickshaw and cab
i.e. c1*(total rikshaw + total cabs)

When he pay c2 for each rikshaw type and each cab type
i.e c2*(m+n)

When he pays c3 for all rikshaws and for all cabs
i.e. c3*(1+1)

When he pays only c4 for all rickshaws and cabs
i.e. c4

You have to consider the combinations also.
example: if c1 is 1 and c2 is 5,
then you should pay c1 for rickshaw or cab rides less than 5.
and for rides greater or equal to 5, paying c2 is feasible.

The aim is to pay minimum.

The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rickshaws and cabs Ramu is going to use.

So, third line contains n integers:
each ith integer specifies the number of rides he took in the ith rickshaw.

Similarly, the fourth line contains m integers:
each ith integer specifies the number of rides he took in the ith rab.

Example:
1
1 3 7 19
2 3
2 5
4 4 4
He would take 2 different rickshaws and 3 different cabs.
He would then take 2 rides in the first rickshaw and the 5 rides in the second.
Similarly, he would take 4 rides in each cab.

You can also watch Prateek bhaiyas video on this problem: https://www.youtube.com/watch?v=CKDFPzX24BY

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.