这是我对 Codechef 上的 Lead Game 问题的解决方案。它运行良好,但需要 2.63 秒和 3.8M 内存,而我看到许多 C 程序在 0.08 秒内完成和 1.6M 内存。我怎样才能让它更快?
import sys
cnt = int(sys.stdin.readline())
match = [[int(x) for x in sys.stdin.readline().split()] for i in range(cnt)]
diff=[]
for i in range(cnt):
if i!=0:
match[i]=[sum(vals) for vals in zip(match[i-1],match[i])]
diff.append([1 if max(match[i])==match[i][0] else 2,abs(match[i][0]-match[i][1])])
maxval = max(diff,key=lambda x:x[1])
sys.stdout.write(str(maxval[0]) + ' ' + str(maxval[1]))