#568
Unrated
Sleeping in Class
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 NN class periods (2N1052\le N\le 10^5), and Elsie logs that Bessie fell asleep aia_i times (1ai10181\le a_i\le 10^{18}) in the ii-th class period. The total number of times Bessie fell asleep across all class periods is at most 101810^{18}.

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 a=[1,2,3,4,5],a=[1,2,3,4,5], then if Elsie combines the second and third class periods the log will become [1,5,4,5][1,5,4,5]. If Elsie then chooses to split the third class period into two, the log can become any of [1,5,0,4,5][1,5,0,4,5], [1,5,1,3,5][1,5,1,3,5], [1,5,2,2,5][1,5,2,2,5], [1,5,3,1,5][1,5,3,1,5], or [1,5,4,0,5][1,5,4,0,5].

Given QQ (1Q1051\le Q\le 10^5) candidates q1,,qQq_1,\ldots,q_Q for Bessie's least favorite number (1qi10181\le q_i\le 10^{18}), 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 NN, and the second contains a1,a2,,aNa_1,a_2,\ldots,a_N. The third contains QQ, followed by QQ lines each containing an integer qiq_i, a candidate for Bessie's least favorite number.

출력

For each qiq_i, compute the minimum number of modifications required for Elsie to convert every entry of the log into qiq_i, or 1-1 if it is impossible.

예제 입력 1

6
1 2 3 1 1 4
7
1
2
3
4
5
6
12

예제 출력 1

6
6
4
5
-1
4
5

점수

In test cases 2-4, N,Q5000N,Q\le 5000In test cases 5-7, all aia_i are at most 10910^9.Test cases 8-26 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.