N,M = list(map(int,input().split()))
T = 0
K = 0
P = 0
for i in range(N):
apple = list(map(int,input().split()))
T += apple[0]
shuguo_number = 0
for j in apple[1:]:
T += j
shuguo_number += abs(j)
if shuguo_number > P:
K = i+1
P = shuguo_number
print('{}{}{}{}{}'.format(T,' ',K,' ',P))
201909-2 小明种苹果(续)
代码贴图-100分:
N = int(input())
T = 0
D = 0
E = 0
drop_list = []
for n in range(N):
apple = list(map(int,input().split()))
number = apple[0]
apple = apple[1:]
# transpose list
for i in apple[::-1]:
# 对于结尾是负数,就一直往前找正数,就是得到了最后的剩余数量,到了正数,加上之后就break
T += i
if i > 0:
# 同时防止最后一个值为0的情况
break
# a is original number
# b is a list which records the shuguo results
a = apple[0]
b = apple[1:]
d = 0
for i in range(len(b)):
if b[i]>0 and b[i]<a:
d+=1
elif b[i] == a:
a = b[i]
else:
a += b[i]
# record the fall tree
if d!=0:
D+=1
drop_list.append(1)
else:
drop_list.append(0)
for i in range(len(drop_list)):
if i == len(drop_list)-1:
if drop_list[i] ==1 and drop_list[0] == 1 and drop_list[1] == 1:
E+=1
break
elif i == len(drop_list)-2:
if drop_list[i] ==1 and drop_list[i+1] == 1 and drop_list[0] == 1:
E+=1
else:
if drop_list[i]==1 and drop_list[i+1] == 1 and drop_list[i+2]==1 :
E+=1
print('{}{}{}{}{}'.format(T,' ',D,' ',E))
可能思路稍显复杂,毕竟是自己思考的过程,还是简单的记录一下自己做题的过程!
多多包涵!