import java.awt.Adjustable;
import java.util.Stack;
import org.junit.Test;
public class Test1 {
@Test
public void testFunc() {
int[] arr = {2,4,5,2,3};
int res = minNum(arr);
System.out.println("res: "+res);
}
//鼓励小朋友发放糖果
public int minNum(int[] score){
if (score.length==0) {
return 0;
}
if (score.length==1) {
return 1;
}
int[] res = new int[score.length];
res[0]=1;
for(int i=1;i<score.length;i++){
if (score[i]>score[i-1]) {
res[i]=res[i-1]+1;
}
else{
res[i]=1;
}
}
for(int i=score.length-2;i>=0;i--){
if (score[i]>score[i+1] && res[i]<=res[i+1]) {
res[i]=Math.max(res[i], res[i+1]+1);
}
}
return sumArray(res);
}
public int sumArray(int[] arr){
int res=0;
for(int ele:arr){
res+=ele;
}
return res;
}
}