Posts

Showing posts from August, 2020

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  space-separated integers  W 1 , W 2 , … , W N . Output For each test case, print a

Random Pair :)

Question:- Chefu is Chef's little brother, he is 12 years old and he is new to competitive programming. Chefu is practicing very hard to become a very skilled competitive programmer and win gold medal in IOI. Now Chefu is participating in a contest and the problem that he is trying to solve states: Given an array  A  of  N  integers, find any  i ,  j  such that  i  <  j  and  A i  +  A j  is maximum possible unfortunately, there's no much time left before the end of the contest, so Chefu doesn't have time to think of correct solution, so instead, he wrote a solution that selects a random pair ( i ,  j ) ( i  <  j ) and output  A i  +  A j . each pair is equiprobable to be selected. Now Chefu wants your help to calculate the probability that his solution will pass a particular input. Input First line contains an integer  T  denoting the number of test-cases. First line of each test-case contains a single integer  N Second line of each test-case contains  N  space-separ