How to solve this question

IEEE is having its AGM next week and the president wants to serve cheese prata after the meeting. The subcommittee members are asked to go to food connection and get P(P<=1000) pratas packed for the function. The stall has L cooks(L<=50) and each cook has a rank R(1<=R<=8). A cook with a rank R can cook 1 prata in the first R minutes 1 more prata in the next 2R minutes, 1 more prata in 3R minutes and so on(he can only cook a complete prata) ( For example if a cook is ranked 2… he will cook one prata in 2 minutes one more prata in the next 4 mins an one more in the next 6 minutes hence in total 12 minutes he cooks 3 pratas in 13 minutes also he can cook only 3 pratas as he does not have enough time for the 4th prata). The webmaster wants to know the minimum time to get the order done. Please write a program to help him out.

Input
The first line tells the number of test cases. Each test case consist of 2 lines. In the first line of the test case we have P the number of prata ordered. In the next line the first integer denotes the number of cooks L and L integers follow in the same line each denoting the rank of a cook.

Output
Print an integer which tells the number of minutes needed to get the order done.

Example
Input:

3

10

4 1 2 3 4

8

1 1

8

8 1 1 1 1 1 1 1 1

Output:

12

36

1

hello @Himanshu-Jhawar-2273952536067590

try to solve it using binary search …

your logic to decide whehter given time is possible or not are as follows->

let say time is T (mid)  and cook i  cooks x paratha then we can say

a[i] *( 1+ 2 + 3...+x) <=T
a[i]  * (x * (x+1))/2 <=T
x*(x+1) <= 2*T/a[i]

x^2 +x - 2*T/[i] <=0

solution of this equation by sridharachary formula
x= (-1 +  sqrt(1+8 * T/ a[i]  )/ 2

so just go to each cook and compute this x. and add it to ur count.

at the end if count >=p return true otherwise return false.
```

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.

can you tell how to solve this ?

https://practice.geeksforgeeks.org/problems/strongly-connected-components-kosarajus-algo/1

hello @Himanshu-Jhawar-2273952536067590

pls read about kosaraju algorithms…

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.