Help me in solving GAME_XI problem

My issue

T=int(input())
for i in range(T):
n,m=map(int,input().split())
bat=list(map(int,input().split()))
bowl=list(map(int,input().split()))
if n<4 or m<4 or n+m<11:
print(-1)
break
else:
bat.sort(reverse=True)
bowl.sort(reverse=True)
score=0
for x in range(3):
score+=bat+bowl
bat.pop(x)
bowl.pop(x)
batbowl=bat+bowl
batbowl.sort(reverse=True)
score+=batbowl[0]+batbowl[1]+batbowl[2]
print(score)

My code

# cook your dish here
T=int(input())
for i in range(T):
    n,m=map(int,input().split())
    bat=list(map(int,input().split()))
    bowl=list(map(int,input().split()))
    if n<4 or m<4 or n+m<11:
        print(-1)
        break
    else:
        bat.sort(reverse=True)
        bowl.sort(reverse=True)
        score=0
        for x in range(3):
            score+=bat[x]+bowl[x]
            bat.pop(x)
            bowl.pop(x)
        batbowl=bat+bowl
        batbowl.sort(reverse=True)
        score+=batbowl[0]+batbowl[1]+batbowl[2]
        print(score)

Traceback (most recent call last):
  File "/mnt/sol.py", line 15, in <module>
    score+=bat[x]+bowl[x]
           ~~~^^^
IndexError: list index out of range

Problem Link: GAME 11 Practice Coding Problem - CodeChef

@saransh2111
the logic is first pick 4 maximum values of batsman and 4 maximum values of bowler.
Then add maximum of ( other 3 maximum batsman, 2 maximum batsman + 1 bowler , 1 maximum batsman + 2 bowler , 3 maximum bowler).

Ya i have used yhe same logic but why my code is not working then

You did some silly mistakes here’s correct version of your code.

# cook your dish here
T=int(input())
for i in range(T):
    n,m=map(int,input().split())
    bat=list(map(int,input().split()))
    bowl=list(map(int,input().split()))
    if n<4 or m<4 or n+m<11:
        print(-1)
    else:
        bat.sort(reverse=True)
        bowl.sort(reverse=True)
        score=0
        for x in range(4):
            score+=bat[0]+bowl[0]
            bat.pop(0)
            bowl.pop(0)
        batbowl=bat+bowl
        batbowl.sort(reverse=True)
        score+=batbowl[0]+batbowl[1]+batbowl[2]
        print(score)

but why range 4 not 3 because range 4 will add 5 players’ score and total 5+5+3=13 players instead of 4+4+3=11

Range is 0 to 4 as in python range(5) means we take a less than 5