 What's up guys, Mike the Coder here today. We are going to talk about The next problem of sphere online judge. Okay, so This problem is called army strength. Basically, you're given the strengths of the monsters of two armies, right? So you're given Two armies one is called Godzilla. The other one is called Mechazilla Okay so in each battle The weakest monster of both of these armies are killed, right? So the weakest monster of both armies are killed If there are several weakest army weakest monsters, but all of them are in the same army Basically, they're saying all of them are the same value in your Army, right? Then one of them at random is killed. Okay? If both armies have at least one of the weakest monsters, then a random monster of Mechazilla's army is killed, okay The war is over if in one of the armies all of the monsters are dead If all the monsters are dead in one of the army the other army one, okay? So basically, I'll explain the test cases What that means right now? So let's say in one test case the first test case is you have one one. So in this case as you see here in this case What's gonna happen is that All these the weakest monster is they're all in the same army, right? So then Yeah, but in this case if both both armies have at least one weak monster Okay, so in this case, let's say this is one is gonna be at Godzilla, right? Godzilla's army and this one's Mechazilla, okay, so This one and one are monsters, right? This one is in Godzilla's army. This one is in Mechazilla's army So if both of them have the the same weak monster Then what's gonna happen is that from this case? It says that a random weakest monster of got Mechazilla's army is killed So in this case, it's just gonna kill off this one and because Mechazilla's army lost has no more no more Monsters here Godzilla wins So the Godzilla wins so that's why in this output the output is Godzilla All right now. Let's look at the other test case The second test case is one three two and Five five right So in this case we have One three two is Godzilla and this one is Mechazilla Okay, so in this case what it's what it's gonna do Remember the weakest monster of them both is killed off So one is the weakest monster of both Godzilla and Mechazilla, so this is killed off Two is the weakest monster of Godzilla and Mechazilla. So this is killed off Three is a weakest monster from Godzilla and Mechazilla so three is killed off In the end Godzilla has no more no more monsters So Godzilla loses and mech is a lot of wins. So that's why the answer for that one is mech is a lot Mech a Godzilla. Yeah, mech is a Godzilla. Okay, so I think you guys should see the pattern of how to How to do solve this problem? So if you if you want to solve this problem, what you would do is that you would actually sort both of them So remember you have one three two five five, right? So I'm gonna sort one three two So it's gonna have one two three and then five five. I'm gonna sort to have five five Now what I'm gonna do is that I'm going to use two pointers first one is gonna start at one of the first value of Godzilla And the second one is going to start at the value of mech a zilla at five. Okay now if If the value at Godzilla is less than the value of mech a zilla. I'm actually going to move the Pointer of Godzilla upward by one. So I'm gonna take this down and I'm gonna move it to the next one and this is basically What this is doing is it's gonna remove the value. We don't technically have to remove it from the array We're just gonna move the pointer up. Okay To showcase that we already that we're removing it. Okay Then if this value of Godzilla the value out the Godzilla is is greater is Less than the value at mech a zilla, which in this case two is less than five So I'm gonna move it up again. So I'm gonna move the pointer down up To three so then what this is doing is it's gonna remove? To and it's gonna go to three. Okay, so basically what I'm doing is I'm every time I have a Value I'm gonna compare the values from the values from the Godzilla's array and the values from mech a zilla's array and the smaller one. I'm going to whichever has a smaller Value I'm gonna move that pointer upwards. Okay, and then in this case three At the end three is less the less than five. So this pointer gets moved upward again. Now once I finish looping through the the array That basically means it's over, right? That means that If I moved all the way past through one of the arrays of Godzilla That means that Godzilla lost right Godzilla is empty. So in this case, I'm going to print out mech a zilla mech a zilla one Okay, now, let's actually go back to a case of now one one. So now go back to the Going back to the case of one one of Godzilla and mech a zilla in this case We have the first pointer pointing down at Godzilla the next one pointing at mech a zilla Okay, um, is the value at Godzilla less than the value of mech a zilla. No, it's not so I What I'm gonna do is I'm gonna actually move the pointer of mech a zilla up by one Okay, so because I move the pointer mech a zilla up by one That means that mech a zilla lost Like if we remove this value and because we're at the end of the array mech a zilla lost So mech a zilla's gone and then Godzilla wins So that's that's the reason why Godzilla wins here So that's basically the gist of the algorithm how you would solve this problem Sort it then use two pointers and then maintain the tracking of the smaller value in each array Whichever is a smaller one just move the pointer up By the time you get to the end of the array and any of what the values of any of them What what that means that it's over and then we just Return whichever one and whichever lost and I think I have the code for that hold up I'm gonna show you guys a code now. I think Army strength I think I'm pretty sure I had a code for this. Let me see if I could go back to oh Status my status. Okay Let's see. Yeah, so the value I got a seed so here. I'm gonna show you guys a code. All right so, yeah Okay, so the the problem about the code is that Whoops Problem about the code is that the test cases are really formatted strangely So if you go back to the test cases, there's like spaces Between each test case so that means you have to ignore the line There's like a line between each test case. So you have to ignore that so For that first, yeah, I had to read in T which is the number of test cases then for that I did cn.ignore to ignore line And I actually could go back and open a new tab And then I could show you guys what I mean by that So in in this case, if you look at the the input statement, there's a there's there's a test case of After the first line of the test case, there's an enter a blank a blank line So we have to we have to ignore that one reading. So that's why I did cn.ignore After the first line of reading T Then what I did was while T is greater than zero that means while my test cases What I have test cases, right? I'm gonna I'm gonna actually read a string input and the reason why I read in string input is because After each test case, there's always a weird blank line See the weird blank line here each of these test cases So I have to actually check for that Otherwise, I'm gonna end up reading in a blank line as in one of the numbers So for that I read in the string input I did get line cn input and that reads in the line Then I check if it's empty. So if this string was empty Right, then I just continue, right? I don't actually Keep reading in more lines. I skip this line. So by doing continue I go back to the top of the test case and then I read in the next line Now if it's not empty Which means it has numbers. So in this case, there's one one here Um, then for that, I'm gonna read in The values that of that into my two numbers So because I already read in the line of input Of my line of my string of input I'm going to put that into two variables called n and m So I'm going to use ss scan f which basically takes your string and um Converts this based on like your space Into two in two numbers. So in this case is a percent d is a placeholder for A number and percent d is a put another place over to a holder for another number So in this case, it basically takes the string And it reads it those value this the string that we have here one one and puts those into two variables called n and m So I do that here n and m Then um for that those two variables represent the size of the array Then I'm going to read in for godzilla and mechazilla. So for that, I create two two Vectors both have a long long l l is long long, right? They have godzilla and mechazilla So for each of them, I'm going to loop through them and I'm going to basically keep reading Godzilla godzilla godzilla and mechazilla mechazilla mechazilla, right over and over again Okay Then what I'm going to do is I'm going to sort both godzilla and mechazilla like we talked before Then I'm going to have two pointers. The first one is i is equal to zero and this points at the First value of godzilla's array. The second one is in j is equal to zero and this is going to point to the first value of mechazilla Okay So now what I'm going to do is while my values of my i Of my index for my godzilla array my pointer of that is less than the End of the array right while it's less than the end of the array and while my other pointer j is less than the end of the array of mechazilla I'm going to do my now. I'm going to do my comparison so I'm going to compare the value of godzilla and the first value of mechazilla so both of these values and Whichever is the smaller one. So in this case godzilla is smaller than mechazilla. I'm going to increase godzilla's pointer of i plus plus Otherwise I increase the pointer of mechazilla j plus plus and that does that Okay, at the end what I need to do is I need to check The value of which one actually won and which one actually lost. So in this case if my Mechazilla reached the end of its array that means mechazilla lost Right, so if my pointer of my mech of my mechazilla reached the end of the array It means mechazilla lost. So I print out godzilla Otherwise I print out mechazilla. So that means that the godzilla won Okay, after we're done done with this we need to Subtract one by the yeah We have to subtract one from our test cases because that means we're done with that test case And then um, I do see and ignore because I have to ignore the next Enter line, right? So in this case, there's another enter line and another Blank line for some reason so I have to ignore that also So yeah, this ignores the next blank line And that's pretty much the gist of the code. I hope you guys understood my Explanation rate com subscribe. I'll check you guys later. Peace