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.

 

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

hide comments
akhil_29071991: 2020-10-17 08:28:17

ac in one go

bismeet: 2020-09-29 15:56:37

Your code has to be in c++ with fastio, else it wont pass anything.

[NG]: It's possible in Python: https://www.spoj.com/ranks/PRATA/lang=PYTH%202.7

Last edit: 2020-09-29 22:12:28
bismeet: 2020-09-29 15:35:40

TLE with Python using BS.

zaidrpm: 2020-09-21 22:18:54

Binary Search solution ( 0.02 s)
BTW. I like cock

Last edit: 2020-09-22 00:48:01
tanuj_yadav_07: 2020-08-20 12:45:48

may be due to divide and conquer

hurayraiit: 2020-08-20 10:46:11

Can anyone tell me why this one is in the segment tree category here (https://a2oj.com/category?ID=25)

darshan_07: 2020-08-01 18:35:31

AC in third go :))
This was a great question on binary search !!!!

sitanshu29: 2020-07-24 06:02:29

priority queue simpe sol
AC in one go

aditya2020: 2020-06-25 16:20:08

could someone pls tell me where I could go wrong in my submission 26195974 . I used priority queue to form min heap. I ran the while loop p times and everytime updated the top position of the heap by the next paratha available by that chef.
All possible test cases work. Ive got no fucking clue as to where it could go wrong.

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

First time in a while in one go


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