#Lutece2834. Rapport Test
Rapport Test
Migrated from Lutece 2834 Rapport Test
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Kanade, Yuzuru, and Yuri are playing Overcooked! 2, a multi-player game that needs much rapport between players. But they seem to have no rapport at all. So they decide to have a test.
There is an array consisting of integers. The test will be performed on this array for times. Yuri, Kanade, and Yuzuru will take an integer away from one subarray of by turns. After an integer is taken away, it will disappear from the array. The only requirement is that the largest integer taken out is strictly less than the sum of the other two. The score for this time is the sum of the three integers they take away. After calculating the score, they will put back these integers to their original positions. If the requirement can't be satisfied, the score is .
Kanade would like to know the maximum scores they can reach each time.
Input
The first line contains one integer --- indicating the size of array .
The second line contains integers, indicating the array . The -th integer indicates .
The third line contains one integer --- indicating the number of tests.
For the next lines, each line contains two integers , indicating the subarray they take integers away from is .
Output
Output lines, the -th line contains the maximum score they can reach in the -th test.
Samples
6
1 9 1 9 8 1
2
4 6
1 6
-1
26
Resources
The 18th UESTC Programming Contest Preliminary