201909-1(Python实现)

# 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实现))