An array consists of number of employees required for each month. ‘Hire’ is the cost of hiring an employee and ‘serv’ is the cost of removing an employee and ‘sal’ is the cost of retaining an employee for a month.Cost for each month will be (no_hires * hire + no_fired * serv + no_retain * sal) Given, the requirement for any month will strictly lie between 1 and 41. What is the minimum possible total cost for the ‘n’ months.
I dont think there are that many possibilities.
Simply for each day calculate the value for all possible hiring,take the max value and add to max value of previous day.
Ie on first day u have only 1 choice,do arr[1] hiring.
On second day , u can do arr[2]-arr[1] < k < arr[2]. Hirings
And so on…
With number of hirings ,u can easily calculate nofired and retain.
Hope this helps.Correct me if i am wrong as the question is not that clear.
"Calculating it for all possible combinations for a day " Can u elaborate more how you are calculating?
By the way yes u can fire only the people who are there in the previous month ,so u can fire only 0-5 people yes u r correct in that
Lets say no_of_employee arr is
arr[]={5,6}
Hire=50,serv=40,sal=30
So on first day ,5 hire (no other option)
So cost1=5*50=250
On 2nd day
Hire. Fired. Retain. Cost
|…| 0. |…| 5. |…| 1 * 50+0 * 40+5 * 30=200
|…| 1. |…| 4. |…| 2 * 50+1 * 40+4 * 30=260
|…| 2. |…| 3. |…| 3 *50+2 * 40+3 * 30=320
|…| 3. |…| 2. |…| 4* 50+3* 40+2* 30=380
|…| 4. |…| 1. |…| 5* 50+4* 40+1 *30=440
|…| 5. |…| 0. |…| 6* 50+5* 40+0* 30=500
So the first option is more feasible
Cost2=200
Ans=cost1+cost2=250+200=450
If i am doing anything wrong,plz correct me.
I could reach to the deduction that for 1 hire only 1 combination exist by:
Let x be no_of employee in prev day
Let y be no.of hired in current day
Let z be req. No of employee in current day
So we have following
So
For all valid y’s:
{
retain+fired=x
y+retain=z
Retain =z-y
Since z and y are constant. So retain is constant
Since retain is constant,fired is constant,ie there is unique solution
}
You have hire cost for hiring, serv cost for firing and sal cost for retaining
There are two cases in it
hire+serv < sal
Then you should hire new employees every month as paying salary will cost more then firing and hiring them again. So find the total number of employees required for n months and calculate the hiring cost and firing cost for n-1 months. Sum will be the answer
sal < hire+serv
In this case, pay salary for the number of emplyees which are required in next month. if more employees are required pay hire price for them and if less are required, remove remaining
The question is extremely unclear. What do you mean by Given, the requirement for any month will strictly lie between 1 and 41. ? Also, whats the constraints for number of months?
If its available on net, can you please give the Q link?