 What's up guys? Mike the Coder here. Today we're going to go over the next problem on Spodge Stamps. This is actually not a hard problem, but I'm going to skip the story because the story is too long to read. You really don't even need to understand the story. Basically, you have a few test cases. You're going to read in the number of test cases, but then you have two numbers. Next line gives you two numbers. The first line tells you how many stamps Lucy wants. How many stamps she actually wants. The next line tells you how many friends she has that she can borrow the stamps from. The third line is the number of stamps from which each of the friends wants to offer. If we look at the test cases, let's go over them right now. The first line, 100, this is the number she wants, the number of stamps she wants. The next line is the number of friends willing to give her stamps. Friends to give stamps. The rest of these, the next line is just the number of stamps per each friend. 14, 17, 42, 9, 23, 57, 9, 23, 57, 23, 57. Now, basically the questions asked us is what is the minimum number of friends she needs to give her stamps in order to reach the 100 that she wants. So what is the minimum number of stamps she needs? Minimum number of friends to give her stamps. If you look at the problems, if you look at the array in this case, you see that this is not really that difficult. So if you think about this, you want to find the minimum number of friends to give her the number of stamps to reach 100. To solve this problem, let's think about this. If I just pick the smallest one starting from 9, pick 9, and then I pick 13, so I just take this 9, then I add it with 13, then I add it with like 17. At this point, it would take three of her friends would have to give her stamps in order to reach 100. That's actually not a good idea because if you start from the smallest and then adding something them up to the right, you're going to end up with way more friends. You have more friends here. That's not what we want. We want the smallest number of friends to give her the stamps. So in order to do that, it's actually better if you sort it by largest to smallest. So if I sort from largest to smallest, so now I get 57 here. And then I have 42. Right. And then I have 23. And then I have 1713 and 9. Right. Now I start adding from the left to the right. You're going to realize that, oh, it's not going to take more than three, right? Because then 57 plus 42 would get you 99 and then 99 plus 23 will get you greater than 100. Yeah, that'll get you that'll get you more than 100. So that's the answer would just be these three. So the answer would be three, three stamps, three friends to give her stamps. So yeah, it's pretty much the gist of the question to solve this problem. Read in the number of stamps you want, read in the number of friends you want, read in your array, sort it from largest to smallest and then just sum up some of every single value. Starting from the beginning to the end. If you get to a point where you reach greater than or equal to the stamps, number of stamps that you want, you just break and you just print out the number of friends. You keep tracking the friends that you have. So yeah, that's pretty much the gist of this problem. So yeah, I'm going to show you the code now. Let's go to my status. So yeah, actually took didn't take that long actually. All right. Oops. Okay. So first thing you got to do we didn't ever test cases T and then after that this is a for loop. To loop from number from one to less than or equal to T. The reason I use a for loop here is because they want you to print out each scenario. So if you go back to the go back to the problem statement, the output, they want you to do is for every like scenario, you have to print out one, two, three. Right. And then, yeah, print out the snare one, two, three. So that's why I had a for loop num equal to one less than or equal to T. Okay. And then now I'm going to read an M and then after that I build my array, which is a vector with the number of values of M and I'll loop through it and read in my array. Okay. After that, I'm going to sort my array from beginning to end and then I pass in greater. So this is going to sort to largest to smallest. That's what it's going to sort it by. Okay. Now I'm going to create an index. I is equal to zero. All right. This index is just going to like loop through to the end of the array. And then when I reach a point where my like total sum is greater than or equal to the value that I want, then I just break. And I could print out this my current index that I'm on. So this current index is telling you how many friends is giving the number of stamps to me. Okay. Current index is equal to I equal to zero. And then I count the total sum that I have for each number of stamps. And that's zero. After this, what I'm going to do is I'm going to loop through from zero to the end of the array, my array. Okay. If my sum that I'm currently have is greater than or equal to n. So n is the number that I want. Right. It's greater than or equal to the end that I break. Right. That's the number of stamps that I want that I break. Otherwise, I'm going to add. So I'm going to pick that element. I'm going to add it. So in this case, it's just going to pick up at 57. After that, it's going to add 42. 23 is the sole sum greater than or equal to 100. Yes. So then it breaks. As we add, it's going to add the current element. And it goes to the next one until the sum is greater than or equal to n. It breaks. Okay. So if the sum is less than n, right, there are certain cases where it's impossible. In this case, like no matter how many, even if you add all the elements of the array, it's still going to be less than the number of stamps, right, that you want. So in this case, just like in the problem statement, you have to print out the scenario number and then print impossible. So that's what I do here. So if the if in the end, the sum is less than n, it's still less than n. If the sum is still less than the number of stamps we want, then it's absolutely impossible because at this point you already summed up the whole value of the array and you don't add it still, you still can't get to your total sum that you want, right? The total value. Okay. So in this case, I just print out scenario, the number, and then I print out the colon and I print impossible. Then, yeah, it's impossible to print out a new line. Otherwise, I just print out scenario, number, print number, print out the current index value, and then I just print out and okay, so this I represents the remember the I represents the current current number and I'm going to current add right the current number of friends that I'm going to include. So that's what this I represents. Right. So then I just print that out and I print a new line and then that's it. So yeah, that was pretty much just the code. There's not much to it. Hope you guys enjoy this video. Come subscribe. I'll check you guys later. Peace.