为拼图编写伪代码

Write a pseudo code for the puzzle

给定某些位置的废物值在 1.01 和 3.00 之间,您一次最多可以携带 3.00 公斤。携带垃圾最少需要多少个袋子?

输入

4
1.30 1.40 1.50 1.60

输出

2

输入

4
1.40 1.70 1.50 1.50

输出

3

伪代码是这样的

double sum=0,max=3.00;

int count=1;

for(i=0;i<n;i++){

    sum+=array[i];

    if(sum>max){

        count++;

        sum-=max;

    }

}

print(count);