 Our guys now we're going to go over the next problem of code forces 645 vision to be Maria breaks the self isolation. So Maria Maria is a active old lady and she's tired of sitting at home. So she decides to have a ceremony against a coronavirus. She has end friends who are also grannies. The ith granny is ready to attend the ceremony provided at the time of their parents. Assuming that there is at least a of I have other grannies there. Note that grannies can come into the yard at the same time. Formerly the granny I agrees to come over if the other grannies who came in earlier or say who came earlier or at the same time with her is greater than or equal to a of I. So this means that it all should the so the ith granny so like the first or second granny will only come at the same time with her if it's greater than or equal to a of I right if it's greater than or equal to whatever value it is. So Maria is the only one at the courtyard first then all the end grannies are still sitting at home at each step Maria selects a subset of grannies none of which have yet to enter the courtyard. So she's going to choose some grannies out of the array. She promises each of them at the time of her appearance that there was at least a of I of other grannies including Maria. So there has to be at least that number of grannies including her in the courtyard. So she can call several grannies at once. In this case the selected grannies will go on a quarter at the same amount of time. She cannot deceive grannies. Okay so that means that if anything strictly less than it is prohibited right anything less than a of I other grannies is prohibited. Please note that if several grannies appear in the yard at the same time then each of them sees each other at the end of the parents. Okay so how this works is that in this example we have n equals 6 which is the number of elements in our array and we have a okay and then at the first step she can take numbers 1 to 5 1 in 1 in 5 so that's going to be this array this element at 1 and this element at 5 1 2 3 4 5 this this element at 5 yeah so that that one so she picks both of the ones right the numbers 1 and 5 are the indexes so they're assuming they're indexing from one but yeah so note that a 1 I is a 1 is less than or equal to 2 and a 5 is 1 is less than or equal to 2 okay so basically they're saying that because the numbers at the indexes 1 and 5 the number the numbers at the index of 1 and 5 are less than or equal to 2 that's why they picked it right because they're going to pick two people and then because the indexes are less than or equal to 2 they pick those two at the second step they could pick indexes 2 3 and 4 and that's 5 4 and wait yeah 5 4 and 5 yeah so they pick 5 4 and 5 and the reason why is because uh if because they're picking 5 grannies at the moment going out they're all these numbers are less than or equal to 5 so that's the reason why they picked it and then the sixth granny can't be called because um the the last one is uh 9 and it's not less than or equal to 6 okay so um this is actually not a hard problem basically you're just gonna have to try to get every single okay so in this problem you're gonna you're trying to pick the the ones where it's less than or equal to whatever uh number of granny you're picking at right so like if i'm going to pick 5 grannies i have to get all all the ones that are less than or equal to 5 right and which is these right and if i'm going to pick like 6 i have to get all the ones less than or equal to 6 right so that's basically it you have to create a counter and then keep keep track of the whichever granny at the current location okay uh i'm gonna i'm gonna show you guys on pen and paper what i mean okay so in the first example we have n equals 6 and then these are the numbers right and basically we're picking at first we're gonna pick 2 because we're including maria so then we're gonna pick two numbers that are less than or equal to 2 so that's 1 and 1 so that's where they pick those first and then after that so like we pick 2 right pick 2 and because these 1 and 1 index 1 and 1 are both less than or equal to we pick those two right so we're gonna pick one uh at one let's or let's assume we're indexing from one right and pick indexes one and five and then um what you could do is you have like a counter that counts the ones that you want to pick first so then after that you want to pick like let's say you pick three but then if you pick three uh there'll be like three of them and if you pick four you need to pick um what whichever numbers are less than four so that would be one four and one and if you pick five whichever numbers less than five which would be one five four five one so if i pick um five the numbers are less than five are going to be at index one two three four and then five right and that's the the numbers are one five four five one so as you can see here i need to find the what the values that are less than or equal to whatever counting i'm counting right so i'm picking two and then i pick a three and find the ones pick four then pick five right so the easiest way to do this is actually to sort then sort the numbers first because if you sort the numbers first you could easily find out which one is less than or equal or which one is greater than equal to the numbers that you're picking out of so in this case if i'm if i sort this i would have one one four five five nine right and then in here i could just easily pick out the ones that are uh the maximum index that is pretty much a less than or equal to whatever number it is so in this case if i'm picking one two three four five the maximum index would be five right this one one two three four five and i would just pick five right so basically the algorithm is works is is that you're just sorting the numbers and then you got to check if um if whatever value i'm at like if whatever value that this is right is less than or equal to my current index that i'm going through so if i'm going through one two three four five six right whatever whichever index then i'm going to get the maximum right i'll get the maximum of that right so and then at that at the end of this pretty much i would have the maximum index that's less than or equal to whichever my current value is so for that all you just have to do is sort it and then loop through it and then check every single value here and then check if it's less than or equal to my index that i'm searching at right remember picking whatever and then if it is i'm going to update my max counter like my max number max number like a number that you're picking what out of and yeah you just get the maximum index that it is so the maximum index which will be five and then you just return so that's that's how you do this problem i'll show you the code now all right guys so this is the code um i'm going to read the number of test cases i'm going to read the size of the array i'm going to create my array i'm going to read in all the values of the array i'm going to sort the array and then i'm going to loop through from i is one up to the number of elements and this is going to i is basically basically just keeping track of the numbers i'm picking out of out of the array right i'm going to pick the ones out of the array out of the array and if uh whichever element that's in the array like this is d of i minus one this is whichever element in the array is less than or equal to my index that then i'm picking out of the number of elements i'm picking out of the array then i just update my counter of the the index i that the maximum index i i'm picking out of max numbers i'm picking out of the array so this integer last is just the the last the largest index i'm picking out of the array right the largest number of numbers i'm picking out of the array and i just update that at the end you also have to include maria because remember maria is in the first one right so you have to add one to include maria so that's the last part of this yeah so yeah that's all you have to do for this question i hope i explained it correctly to you guys pretty much you have to check the numbers that you're picking out of the array and making sure that the lesson are equal to your the i'm making sure it's the the elements of that is less than or equal to the numbers are picking out of the array if it is then we're going to update the max counter to make sure that it's the maximum number the maximum index the maximum number of elements are picking out of the array so yeah that's what i did here yeah that's all you have to do for your com subscribe i'll try to do the next problem i couldn't finish the the next problem in the contest but i'm going to try to i'm going to up solve it now so yeah i'll check you guys later