#PU1213. USACO 2022 February Contest, Platinum — Problem 2. Sleeping in Class
USACO 2022 February Contest, Platinum — Problem 2. Sleeping in Class
USACO 2022 February Contest, Platinum — Problem 2. Sleeping in Class
题目描述
Bessie the cow was excited to recently return to in-person learning! Unfortunately, her instructor, Farmer John, is a very boring lecturer, and so she ends up falling asleep in class often. 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 ways Elsie may modify the log are by combining two adjacent class periods or splitting a class period into two. For example, if then if Elsie combines the second and third class periods the log will become . If Elsie then chooses to split the third class period into two, the log can become any of , , , , or . Given () candidates for Bessie's least favorite number (), for each of them help Elsie compute the minimum number of modifications to the log that she needs to perform so that all the numbers in the log become the same.
输入格式
The first line of each test case contains , and the second contains . The third contains , followed by lines each containing an integer , a candidate for Bessie's least favorite number.
输出格式
For each , compute the minimum number of modifications required for Elsie to convert every entry of the log into , or if it is impossible.
数据范围
In test cases 2-4, In test cases 5-7, all are at most . Test cases 8-26 satisfy no additional constraints. Problem credits: Jesse Choe and Benjamin Qi
样例
样例 1
6
1 2 3 1 1 4
7
1
2
3
4
5
6
12
6
6
4
5
-1
4
5
Elsie needs at least four modifications to convert the log into all 3s.
1 2 3 1 1 4
-> 3 3 1 1 4
-> 3 3 1 5
-> 3 3 6
-> 3 3 3 3
It is impossible for Elsie to convert the log into all 5s, which is why the
correct output for that candidate is $-1$.