#P2300. 合并神犇
合并神犇
Description
The shen niu are standing in a line solving problems. Each shen niu has an ability value . loidc feels uncomfortable that the abilities of nearby gold medalists vary widely, so he decides to humanely merge the shen niu.
loidc wants the ability values to be nondecreasing from left to right. Each time, he may choose one shen niu and merge him into one of his two adjacent shen niu. The ability of the new shen niu after the merge equals the sum of the two participants’ abilities. After each merge, the two participants disappear and are replaced by the merged shen niu. The merged shen niu cannot be split again. Therefore, after each merge, the total number of shen niu decreases by .
loidc wants to know the minimum number of merges needed to achieve his goal.
Input Format
The first line contains an integer .
The second line contains integers, where the -th integer is .
Output Format
Output a single integer, the minimum number of merges loidc needs.
8
1 9 9 4 1 2 2 9
3
Hint
Constraints:
- For of the testdata, .
- For of the testdata, , , and the are randomly generated.
Translated by ChatGPT 5
京公网安备 11011102002149号