Posts

Bowling Strategy :) (Codechef Contest Problem)

  Question:- In a cricket game, an  over  is a set of six valid deliveries of balls performed by one player ― the  bowler  for this over. Consider a cricket game with a series of  N overs (numbered  1 through  N ) played by  K players (numbered  1 through  K ). Each player may be the bowler for at most  L overs in total, but the same player may not be the bowler for any two consecutive overs. Assign exactly one bowler to each over in such a way that these rules are satisfied or determine that no such assignment exists. Input The first line of the input contains a single integer  T  denoting the number of test cases. The description of  T  test cases follows. The first and only line of each test case contains three space-separated integers  N ,  K  and  L Output For each test case: If there is no valid assignment of bowlers to overs, print a single line containing the integer  − 1 . O...

Chef And Work :) (Codechef August Cook-Off Contest Problem)

Question:-   Chef has  N  small boxes arranged on a line from  1  to  N . For each valid  i , the weight of the  i -th box is  W i . Chef wants to bring them to his home, which is at the position  0 . He can hold any number of boxes at the same time; however, the total weight of the boxes he's holding must not exceed K at any time, and he can only pick the i-th box if all the boxes between Chef's home and the i-th box have been either moved or picked up in this trip. Therefore, Chef will pick up boxes and carry them home in one or more round trips. Find the smallest number of round trips he needs or determine that he cannot bring all boxes home. Input The first line of the input contains a single integer  T  denoting the number of test cases. The description of  T  test cases follows. The first line of each test case contains two space-separated integers  N  and  K . The second line contains  N ...