Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在codechef(领先游戏)中得到错误答案_Python_Algorithm_Data Structures - Fatal编程技术网

Python 在codechef(领先游戏)中得到错误答案

Python 在codechef(领先游戏)中得到错误答案,python,algorithm,data-structures,Python,Algorithm,Data Structures,输入的第一行将包含一个整数N(N≤ 10000)表示游戏中的回合数。一旦所有回合结束,在游戏中任何回合结束时领先最大的玩家即被宣布为赢家。您的输出必须由一行组成,其中包含两个整数W和L,其中W为1或2,表示赢家,L为赢家获得的最大领先。 当我在codechef中提交这个答案时,我得到了错误的答案。我不知道为什么。有人能帮我找出我的代码出了什么问题吗? 范例 输入: 5 140 82 89 134 90 110 112 106 88 90 Output: 1 58 在“领先游戏”中,每一个领

输入的第一行将包含一个整数N(N≤ 10000)表示游戏中的回合数。一旦所有回合结束,在游戏中任何回合结束时领先最大的玩家即被宣布为赢家。您的输出必须由一行组成,其中包含两个整数W和L,其中W为1或2,表示赢家,L为赢家获得的最大领先。 当我在codechef中提交这个答案时,我得到了错误的答案。我不知道为什么。有人能帮我找出我的代码出了什么问题吗? 范例

输入:

5
140 82
89 134
90 110
112 106
88 90
Output:

1 58

在“领先游戏”中,每一个领先优势都是由得分的累积差异决定的,但是在这里,你用每一个新的得分来寻找领先优势,这是错误的

使用此代码:

testcases = int(input())

#cumulative score for player 1 and 2
c1=0
c2=0
max_lead=0

for i in range(testcases):
    player1,player2 = map(int,input().split())
    
    # determine the cumulative score
    c1+=player1
    c2+=player2
    
    if c1>c2:
        lead = c1-c2
        if lead > max_lead:
            max_lead = lead
            w=1
    else:
        lead = c2-c1
        if lead > max_lead:
            max_lead = lead
            w=2
              
print(w,max_lead)

您还可以添加一个输入示例吗?请进一步解释如何在断言中显示输出,以及它作为错误返回的内容。
testcases = int(input())

#cumulative score for player 1 and 2
c1=0
c2=0
max_lead=0

for i in range(testcases):
    player1,player2 = map(int,input().split())
    
    # determine the cumulative score
    c1+=player1
    c2+=player2
    
    if c1>c2:
        lead = c1-c2
        if lead > max_lead:
            max_lead = lead
            w=1
    else:
        lead = c2-c1
        if lead > max_lead:
            max_lead = lead
            w=2
              
print(w,max_lead)