贪心算法,先每个人发放1K,然后遍历,把不满足的厨师的奖金调整到当前满足的状态,然后再遍历,一直到所有厨师都满足。

import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            int n = scan.nextInt();
            int[] nums = new int[n];
            for(int i=0;i<n;i++){
                nums[i]=scan.nextInt();
            }
            fun(nums);
        }
    }
    
    private static void fun(int[] nums){
        int len=nums.length;
        int[] res=new int[len];
        Arrays.fill(res,1);
        boolean allCheck=false;
        while(!allCheck){
            allCheck=true;
            for(int i=0;i<len;i++){
                if(i==0){
                    if(nums[0]>nums[1]&&res[0]<=res[1]){
                        allCheck=false;
                        res[0]=res[1]+1;
                    }
                }else if(i==len-1){
                    if(nums[i]>nums[i-1]&&res[i]<=res[i-1]){
                        allCheck=false;
                        res[i]=res[i-1]+1;
                    }
                }else{
                    if(nums[i]>nums[i-1]&&nums[i]>nums[i+1]){
                        if(res[i]<=res[i-1]||res[i]<=res[i+1]){
                            allCheck=false;
                            res[i]=Math.max(res[i-1],res[i+1])+1;
                        }
                    }else if(nums[i]>nums[i-1]){
                        if(res[i]<=res[i-1]){
                            allCheck=false;
                            res[i]=res[i-1]+1;
                        }
                    }else if(nums[i]>nums[i+1]){
                        if(res[i]<=res[i+1]){
                            allCheck=false;
                            res[i]=res[i+1]+1;
                        }
                    }
                }
            }
        }
        int sum=0;
        for(int i:res){
            sum+=i;
        }
        System.out.println(sum);
    }
}