第一题试了各种测试案例,都通过了!但是AC一直是0
def totalprice():
objnum,peoplenum=map(int,(input().split()))objprice = list(map(int,input().split()))
objs = {}
for i in range(objnum):
objs[i] = []
totalprice = 0
right_price = 0
left_price = 0
for i in range(peoplenum):
operators = int(input())
for j in range(operators):
op = list(input().split())
if op[1] == 'keep':
continue
if op[0]=='left' and op[1]=='take':
if objs[int(op[2])-1] == []:
left_price = objprice[int(op[2])-1]
totalprice+=left_price
if objs[int(op[2])-1] != []:
left_price = objs[int(op[2])-1].pop()
totalprice += left_price
if op[0]=='left' and op[1]=='return':
objs[int(op[2])-1].append(left_price)
totalprice-=left_price
if op[0]=='right' and op[1]=='take':
if objs[int(op[2])-1] == []:
right_price = objprice[int(op[2])-1]
totalprice = totalprice + right_price
if objs[int(op[2])-1] != []:
right_price = objs[int(op[2])-1].pop()
totalprice += right_price
if op[0]=='right' and op[1]=='return':
objs[int(op[2])-1].append(right_price)
totalprice-=right_price
print(totalprice)
print('\n')
if __name__ == '__main__':
totalprice()
全部评论
(0) 回帖