Given total number of hours, how to find the working hours per day so as to finish the work with the total number of days?

78 Views Asked by At

I am given total number of days(d).I am also given 'n' numbers each representing how many hours of work I can do on the i'th day.Now I have to find the minimum number of work rate(hours/per day) that I can use to finish the work within the total number of days. Example:- n = 4(total days for working) and d= 5(deadline number of days) Hours of work needed per i'th day = 7 3 2 4. Here, I can dedicate 2 days to the first day(7) so that I can finish the work in 5 days at a rate of 4 hours/day. Now, I have come up with a loop that would loop over the speeds from 1 and as soon as I find a speed which manages to finish all the work in 5 days, then I break out of it and print it.However, I was wondering if there is a better way/faster way to solve this problem. EDIT-It seems as if the question was not clear.So, what I have to do is I have to is to find the minimum work rate at which I can complete each days work within the given deadline(d).I CAN allot more than 1 day to finish off a days work if that helps me to get a lower work rate.