題目
大熊貓,俗稱“胖達”,會排隊喫盆盆奶。它們能和諧喫奶的前提,是它們認爲盆盆奶的分配是“公平”的,即:更胖的胖達能喫到更多的奶,等胖的胖達得喫到一樣多的奶。另一方面,因爲它們是排好隊的,所以每隻胖達只能看到身邊胖達的奶有多少,如果覺得不公平就會搶旁邊小夥伴的奶喫。
已知一隻胖達每次最少要喫 200 毫升的奶,當另一份盆盆奶多出至少 100 毫升的時候,它們才能感覺到是“更多”了,否則沒感覺。
現在給定一排胖達的體重,請你幫飼養員計算一下,在保持給定隊形的前提下,至少應該準備多少毫升的盆盆奶?
輸入格式:
輸入首先在第一行給出正整數 n(≤104),爲胖達的個數。隨後一行給出 n 個正整數,表示 n 只胖達的體重(公斤)。每個數值是不超過 200 的正整數,數字間以空格分隔。
輸出格式:
在一行中輸出至少應該準備多少毫升的盆盆奶。
輸入樣例:
10
180 160 100 150 145 142 138 138 138 140
輸出樣例:
3000
樣例解釋:
盆盆奶的分配量順序爲:
400 300 200 500 400 300 200 200 200 300
解題思路
N = int(input())
inputList = list(map(int, input().split()))
# N = int("10")
# inputList = list(map(int, "180 160 100 150 145 142 138 138 138 140".split()))
length = len(inputList)
resList1 = [0]*len(inputList)
for index in range(0,len(inputList)):
# print(index)
last = inputList[index-1] if index !=0 else 200
val = inputList[index]
lastQuanzhong = resList1[index-1] if index !=0 else 0
if val == last:
resList1[index] = lastQuanzhong
elif val > last:
resList1[index] = lastQuanzhong+1
elif val < last:
resList1[index] = 0
# print(resList1)
resList2 = [0]*len(inputList)
for index in range(len(inputList)-1,-1,-1):
# print(index)
last = inputList[index+1] if index !=len(inputList)-1 else 200
val = inputList[index]
lastQuanzhong = resList2[index+1] if index !=len(inputList)-1 else 0
if val == last:
resList2[index] = lastQuanzhong
elif val > last:
resList2[index] = lastQuanzhong+1
elif val < last:
resList2[index] = 0
# print(resList2)
resList = []
for i in range(length):
res = 200 + max(resList1[i],resList2[i])*100
resList.append(res)
print(sum(resList))