Skip to main content

## Watching CPL Codechef January 2021 solution || Watching CPL codechef problem editorial 2021-

### Problem statement-

Get excited, folks, because it is time for the final match of Codechef Premier League (CPL)!

Mike and Tracy also want to watch the grand finale, but unfortunately, they could not get tickets to the match. However, Mike is not someone who gives up so easily — he has a plan to watch the match.

The field where the match is played is surrounded by a wall with height $K$. Outside, there are $N$ boxes (numbered $1$ through $N$). For each valid $i$, the $i$-th box has a height ${H}_{i}$.

Mike wants to take some boxes and stack them on top of each other to build two towers. The height of each tower is the sum of heights of all the boxes that form it. Of course, no box may be in both towers. The height of each tower should be at least $K$. Then Mike can climb on top of one tower and Tracy on top of the other, and they can watch the match uninterrupted!

While Mike is busy stacking the boxes, Tracy would like to know the smallest number of boxes required to build two towers such that each of them has height at least $K$, or at least that it is impossible to build such towers. Can you help Tracy?

### 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 ${H}_{1},{H}_{2},\dots ,{H}_{N}$.

### Output

For each test case, print a single line containing one integer — the smallest number of boxes required to build two towers, or $-1$ if it is impossible.

### Constraints

• $1\le T\le 5$
• $1\le N,K\le 4,000$
• $1\le {H}_{i}\le {10}^{5}$ for each valid $i$

### Subtasks

Subtask #1 (30 points):

• $1\le N,K\le 100$
• $1\le {H}_{i}\le 100$ for each valid $i$

Subtask #2 (70 points): original constraints

### Example Input

2
8 38
7 8 19 7 8 7 10 20
4 5
2 10 4 9


### Example Output

7
2


### Explanation

Example case 1: The first tower can be built with boxes $8+10+20=38$ and the second tower with boxes $7+7+8+19=41$. In this case, the box with height $7$ is left unused.

Example case 2: We only need the box with height $10$ for one tower and the box with height $9$ for the other tower.

### Solution -

Hint- other test cases.
8 15
10 7 7 5 1 1 1 1
output - 5

This problem is based on dynamic programming you need to learn the dynamic programming concept first.
where DP[i][k] represents minimum boxes required to make at least k hight till ith index.
we will use the suffix array here to find whether it is possible to make another box of height k.
finally, we will print the optimal answer.
this question is similar to the 0/1 knapsack problem .
Refer this video  for better understanding -

Join telegram channel for code and editorial.-https://t.me/competitiveProgrammingDiscussion

### Vaccine Distribution Codechef December Long challenge solution 2020

Vaccine Distribution  Codechef December Long challenge solution 2020- This Problem vaccine distribution is taken from December long challenge 2020. lets read problem statement. Problem statement- Finally, a COVID vaccine is out on the market and the Chefland government has asked you to form a plan to distribute it to the public as soon as possible. There are a total of  N N  people with ages  a 1 , a 2 , … , a N a 1 , a 2 , … , a N . There is only one hospital where vaccination is done and it is only possible to vaccinate up to  D D  people per day. Anyone whose age is  ≥ 80 ≥ 80  or  ≤ 9 ≤ 9  is considered to be  at risk . On each day, you may not vaccinate both a person who is at risk and a person who is not at risk. Find the smallest number of days needed to vaccinate everyone. Input The first line of the input contains a single integer  T T  denoting the number of test cases. The description of  T T  test cases follows. The first line of each test case contains two space-separ

### Codechef February long challenge solution 2021

Codechef February  long challenge solution 2021- Hey guys Welcome Again, A small update CodeChef February  long challenge solution 2021 starting from 1st week of beb  2021 . Codechef long challenge is one of the popular contests of CodeChef you should participate in codechef Feb  long challenge.This is first contest of codechef in 2021 so good luck. And wish you happy new year. Contest link- https://www.codechef.com/FEB21/?itm_medium=navmenu&itm_campaign=FEB21 I will post the solution after Contest.Stay tuned. About CodeChef  February  long challenge solution 2021: CodeChef Long Challenge is a 10-day monthly coding contest where you can show off your computer programming skills. The significance being - it gives you enough time to think about a problem, try different ways of attacking the problem, read the concepts etc. If you’re usually slow at solving problems and have ample time at hand, this is ideal for you. We also put in a lot of efforts in getting quality problems, w

### Merge Two sorted array Without Extra Space

Problem statement-  Given two sorted arrays arr1[] and arr2[] of sizes N and M in non-decreasing order. Merge them in sorted order without using any extra space. Modify arr1 so that it contains the first N elements and modify arr2 so that it contains the last M elements.    Example 1: Input:  N = 4, arr1[] = [1 3 5 7]  M = 5, arr2[] = [0 2 6 8 9] Output:  arr1[] = [0 1 2 3] arr2[] = [5 6 7 8 9] Explanation: After merging the two  non-decreasing arrays, we get,  0 1 2 3 5 6 7 8 9.   Example 2: Input:  N = 2, arr1[] = [10, 12]  M = 3, arr2[] = [5 18 20] Output:  arr1[] = [5 10] arr2[] = [12 18 20] Explanation: After merging two sorted arrays  we get 5 10 12 18 20. Your Task: You don't need to read input or print anything. You only need to complete the function merge() that takes arr1, arr2, N and M as input parameters and modifies them in-place so that they look like the sorted merged array when concatenated. Expected Time Complexity:  O((n+m) log(n+m)) Expected Auxilliary Space: O(1