Sorry about that. I just took the C solution I wrote when I was new to SPOJ. Here is a better solution, which still TLEs. I am new to python, please bear with my naive implementation and style of coding
#!/usr/bin/python
import sys
import psyco
def main():
file = sys.stdin
ip = file.read()
ip = ip.split()
t = int(ip[0])
ip = ip[1:]
while t:
t -= 1
ng = int(ip[0])
nm = int(ip[1])
ng_max = 0
nm_max = 0
for i in ip[2:2 + ng]:
if int(i) > ng_max:
ng_max = int(i)
for i in ip[2 + ng:2 + ng + nm]:
if int(i) > nm_max:
nm_max = int(i)
ip = ip[2 + ng + nm:]
if ng_max >= nm_max:
print 'Godzilla'
else:
print 'MechaGodzilla'
if __name__ == '__main__':
main()
The solution is correct, I verified by writing a C program. Is there an even faster algorithm which I should use or is it my implementation that needs improvement?