PRATA - Roti Prata

no tags 

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.



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.


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




4 1 2 3 4
1 1
8 1 1 1 1 1 1 1 1

hide comments
ayush_130: 2020-05-29 20:40:54

First time in a while in one go

bhati_r45: 2020-05-15 17:14:22

binary search jinda baad

az_09_18je0028: 2020-04-18 20:16:02

brilliant one,mind blowing...the use of quadratic equation is awesome::)today i ate parathas because of this ::)lol..

smso: 2020-04-15 08:40:51

quadratic sequence

deepu2345: 2020-04-14 19:38:34

accepted :)

arsundram: 2020-04-04 23:04:54

AC in one Go!! ;)

dkkv0000: 2020-01-27 12:34:13

binary search + quadratic equation rocks

aj54: 2019-12-24 15:41:37

Binary Search and AC in one go!

scorpy1: 2019-09-13 18:09:59

AC with Binary Search

aayush_b1999: 2019-08-03 22:56:35

let max_rank=(the max rank in the given array)
let p=number of prata req.
upper_limit=(p*(2*max_rank+(p-1)*max_rank))/2 (sum of p terms in ap)

Added by:Saransh Bansal
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem- NTU IEEE codejam 2011