How To Solve Techgig Code Gladiators Problems of 2020

Solution of Xelsior
  

Win or Lose 

A new fighting game has become popular. There is n number of villains in it, each having some strength. There are n players in the game with each having some energy. The energy is used to kill the villains. A villain can be killed only if the energy of the player is greater than the strength of the villain.



Maxi is playing the game and at a particular time wants to know if it is possible for him to win the game or not with the given set of energies and strengths of players and villains. Maxi wins the game if his players can kill all the villains with the allotted energy.



Input Format

The first line of input consists of a number of test cases, T.

The first line of each test case consists of a number of villains and player, N.

The second line of each test case consists of the N space-separated by strengths of Villains.

The third line of each test case consists of N space-separated by the energy of players.




Constraints

1<= T <=10

1<= N <=1000

1<= strength , energy <=100000



Output Format
For each test case, Print WIN if all villains can be killed else print LOSE in separate lines.

Sample TestCase 1
Input
1
6
112 243 512 343 90 478
500 789 234 400 452 150
Output
WIN

Explanation

For the given test case, If we shuffle the players and villains, we can observe that all the villains can be killed by players.


As all the villains can be killed by the players, MAXI will WIN the game. Thus, the final output is to WIN.

How to handle this problem:

  • So, first, we make a line of code to take input from the user (Such as the number of the test case).

  • Now, make a variable named count and set as 0.

  • Then, we will make a result list that stores the result of the input.

  • Then we will iterate the while loop for checking the number of the test cases.

  • Then again, we will take the input of the number of players from the user.

  • Now the next step is to split the input.

  • Now we will reverse the input of a number of players and villain.



The solution of the problem:

def main():
    # First we will take the number of test cases. 
    testCases=int(input())
    
    # Then we will take the count variable for store the value.
    # And result list for store the answer.
    count=0
    result=[ ]
   
# Now we will run the while loop for take the input according the number of test cases. 
   
while testCases>0:
        # Now we will take the number of player of each team. 
  
     numberOfPlayer=int(input())
  
     # Then we will take the input of the stregth of both the team.
   
     villian=[int(x) for x in raw_input().strip().split()]        
        player=[int(x) for x in raw_input().strip().split()]
        # Now we Will reverse the strength of the the players.
  
     villian.sort(reverse=True)
        player
        player.sort(reverse=True)
        start=0

        # Then we will compare the strength of the players.
    
    for i in range(numberOfPlayer):
            for j in range(start,numberOfPlayer)
        start=0
     
  # Then we will compare the strength of the players.
     
  for i in range(numberOfPlayer):
            for j in range(start,numberOfPlayer):
                if 
                if player[i]>villian[j]:
                    start=j+1
                    count+=1
                    break
        if (count==numberOfPlayer):
            result.append("WIN") 
            testCases-=1
        else:
            result.append("LOSE")
            testCases-=1
        count=0
   
# Then we will print the result.
    for result in result:
        print(result)
main()

# This code is contributed by Ankur Patel.
Input
2
6
10 20 50 100 500 400 
30 20 60 70 90 490 
5
10 20 30 40 50 
40 50 60 70 80 
Output
LOSE
WIN


If you have a better solution or query, please share in comment or Email.
Next Post Previous Post
6 Comments
  • Python
    Python September 11, 2020 at 10:47 AM

    Thanks for sharing all the information with us all.
    python Online Training

    • Ankur Ranpariya
      Ankur Ranpariya September 26, 2020 at 12:12 PM

      Welcome

  • Praveen Kumar's Portfolio Website
    Praveen Kumar's Portfolio Website December 16, 2020 at 12:39 PM

    Can you give me the same code in java

  • Satyajit Das
    Satyajit Das January 21, 2021 at 11:17 AM

    def main():
    testCases=int(input())
    count=0
    result=[]
    while testCases>0:
    numberOfPlayer=int(input())
    villian=[int(x) for x in raw_input().strip().split()]
    player=[int(x) for x in raw_input().strip().split()]
    villian.sort(reverse=True)
    player
    player.sort(reverse=True)
    start=0
    for i in range(numberOfPlayer):
    for j in range(start,numberOfPlayer):
    if player[i]>villian[j]:
    start=j+1
    count+=1
    break
    if (count==numberOfPlayer):
    result.append("WIN")
    testCases-=1
    else:
    result.append("LOSE")
    testCases-=1
    count=0
    for result in result:
    print(result)
    main()

  • Unknown
    Unknown January 28, 2021 at 9:09 PM

    could you give me same code with nodejs or js

  • prasad
    prasad February 6, 2021 at 5:52 PM

    code pls

Add Comment
comment url