#P3889. [GDOI2014] 吃
[GDOI2014] 吃
Description
Senior Brother W had planned for a long time and finally succeeded in opening a sushi restaurant in BG.
Just as he was still excited, bad news came: foodie Senior Sister L actually learned about this and was on her way. Senior Brother W instantly felt a chill, but being clever, he immediately came up with a strategy to deal with Senior Sister L.
When Senior Sister L arrived at the sushi restaurant, she first looked around and found that she was the only customer. Below are her selection rules:
- The sushi in the restaurant is arranged in a single row of plates, numbered from to from left to right.
- The number of sushi on each plate is fixed and protected by a glass cover.
- At each selection time, Senior Sister L may choose one plate from a continuous interval , and then choose another plate outside that interval (if there are plates outside the interval).
Senior Sister L finds that the chefs here work very fast and can always restore the sushi counts to their original numbers before the next selection time.
As a foodie with standards, after selecting two plates, Senior Sister L will decide to eat exactly pieces of sushi per bite, such that both plates can be finished exactly with no leftovers. For example, if the two plates contain and pieces, then or will finish both plates exactly. If the two plates contain and pieces, then only works.
Senior Sister L does not care about the total amount of food; she cares about the feeling of eating multiple pieces in one bite. Thus, if she can eat pieces per bite, her joy value is . If she cannot select two plates, her joy value is .
Given the number of sushi on each plate, Senior Sister L wants to know, after each selection time, what is the maximum joy value she can obtain.
Input Format
- The first line contains an integer , the number of sushi plates.
- The second line contains integers , where is the number of sushi on the -th plate.
- The third line contains an integer , the number of selection times.
- The next lines each contain two integers with , as described above.
Output Format
Output lines. The -th line contains the maximum possible joy value for the -th selection time.
5
1 2 3 4 5
2
2 3
2 4
2
1
5
2 4 8 16 32
2
3 4
2 3
16
8
Hint
Sample explanation:
- In sample 1, for the first selection time, you can choose and , so Senior Sister L can eat pieces per bite and finish both plates exactly. For the second selection time, no matter which two plates she chooses, she can only eat piece per bite.
- In sample 2, for the first selection time, she can choose and . For the second selection time, she can choose and or and .
Constraints:
- For 20% of the testdata, , , .
- For 50% of the testdata, , , .
- For 100% of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号