小友正在优化财务报表分析功能。给定一个由不同整数构成的数组revenues,每个元素表示在不同时间段内的收入。我们用以下方式定义一个与revenues长度相同的数组maxDurations:
maxDurations[i]是一个子数组 revenues[l..r]的最大长度,该子数组中的最大收入等于revenues[i]。
返回数组 maxDurations。
注意,子数组是数组的连续部分。
第一行输入N,表示数组的长度
输入长度为N的数组的各个元素
maxDurations
输入
6
1 3 2 4 3 5
输出
1 3 1 5 1 6
说明
对于 revenues[0],最长的子数组,其中最大值为 1,是 nums[0..0],所以 maxDurations[0]=1。
对于 revenues[1],最长的子数组,是 revenues[0..2],其中最大值为 3,所以 maxDurations[1]= 3。
对于 revenues[2],最长的子数组,是 revenues[2..2],其中最大值为 2,所以 maxDurations[2]=1.
对于 revenues[3],最长的子数组,是revenues[0..4],其中最大值为4,所以maxDurations[3]=5
对于 revenues[4],最长的子数组,是 nums[4..4],其中最大值为 3,所以 maxDurations[4]=1
对于 revenues[5],最长的子数组,是 nums[0..5],其中最大值为5,所以 maxDurations[5]=6。
扫码备注加群即可,期待您的到来~
By signing up a CodeFun2000 universal account, you can submit code and join discussions in all online judging services provided by us.