每组数据为n+1个正整数单空格分割,其中第一个数为参赛厨师的人数,后面n个数为每位厨师的得分(0-100)
输出至少需要多少K的奖金
10 60 76 66 76 85 55 61 71 84 62
20
data = [int(x) for x in input().split()] data.pop(0) def count(n): return n*(n+1)//2 up,down = 0,0 old_d,cur_d = 0,0 res = 0 for i in range(1,len(data)): if data[i]>data[i-1]: cur_d = 1 elif data[i]<data[i-1]: cur_d = -1 else: cur_d = 0 if old_d==-1 and cur_d >=0 or old_d==1 and cur_d ==0: #先降再平升 或者先升在平 res+=count(up)+count(down)+max(up,down) up,down = 0,0 # if data[i]>data[i-1]: up+=1 elif data[i]<data[i-1]: down +=1 else: res+=1 old_d = cur_d res+=count(up)+count(down)+max(up,down)+1 print(res)
def score(num): res = [1 for _ in range(len(num))] for i in range(len(num)-1): if num[i]<num[i+1]: res[i+1] = res[i]+1 for j in range(len(num)-2,-1,-1): if num[j]>num[j+1]: res[j] = max(res[j],res[j+1]+1) return sum(res) if __name__=='__main__': num = list(map(int,input().split())) person = num[1:] print(score(person))