美文网首页
201909-1(Python实现)

201909-1(Python实现)

作者: tmax | 来源:发表于2019-12-09 23:01 被阅读0次
    # from operator import itemgetter
    import functools
    n, m = input().split()
    n, m = int(n), int(m)
    trees = []
    totalNum = 0
    for i in range(n):
        mList = list(map(int, input().split()))
        num = 0
        for ele in  mList:
            num += ele
        trees.append( (i+1, mList[0]-num ) )
        totalNum += num
    
    # trees.sort(key = lambda x:(int(x[1]), int(x[0])), reverse = True)
    # 表示按先第二项,然后按照第一项排序,均为降序排列
    
    #trees.sort(key = itemgetter(1), reverse = True)
    
    def cmp(a, b):#升序
        if a>b:
            return 1
        else:
            return -1
    
    def myCmp(a, b):
        if a[1]==b[1]:
            return cmp(a[0], b[0])
        else:
            return -cmp(a[1], b[1])
    
    trees.sort(key=functools.cmp_to_key(myCmp))
    
    print(totalNum, trees[0][0], trees[0][1])
    #print(trees)
    

    相关文章

      网友评论

          本文标题:201909-1(Python实现)

          本文链接:https://www.haomeiwen.com/subject/rkxwgctx.html