2054: [USACO 2022 February Contest Bronze] Problem 1. Sleeping in Class
题目描述
Farmer John has noticed that Bessie has not been paying attention in class. He has asked another student in class, Elsie, to keep track of the number of times Bessie falls asleep in a given class. There are class periods (), and Elsie logs that Bessie fell asleep times () in the -th class period. The total number of times Bessie fell asleep across all class periods is at most .
Elsie, feeling very competitive with Bessie, wants to make Farmer John feel like Bessie is consistently falling asleep the same number of times in every class -- making it appear that the issue is entirely Bessie's fault, with no dependence on Farmer John's sometimes-boring lectures. The only way Elsie may modify the log is by combining two adjacent class periods. For example, if then if Elsie combines the second and third class periods the log will become .
Help Elsie compute the minimum number of modifications to the log that she needs to make so that she can make all the numbers in the log equal.
输入
The first line contains , the number of test cases to be solved. The test cases follow, each described by a pair of lines. The first line of each pair contains , and the second contains .
It is guaranteed that within each test case, the sum of all values in
is at most . It is also guaranteed that the sum of over all test cases is at most .输出
样例输入
3
6
1 2 3 1 1 1
3
2 2 3
5
0 0 0 0 0
样例输出
3
2
0
提示
For the first test case in this example, Elsie can change her log to consist solely of 3s with 3 modifications.
1 2 3 1 1 1 -> 3 3 1 1 1 -> 3 3 2 1 -> 3 3 3
For the second test case, Elsie can change her log to 7 with 2 modifications.
2 2 3 -> 2 5 -> 7
For the last test case, Elsie doesn’t need to perform any operations; the log already consists of equal entries.