#P4587. [FJOI2016] 神秘数
[FJOI2016] 神秘数
Description
The mysterious number of a multiset is defined as the smallest positive integer that cannot be represented as the sum of a submultiset of . For example, with , we have: , , , , , , .
cannot be represented as the sum of a submultiset of , so the mysterious number of is .
You are given a sequence of length consisting of positive integers, and queries. Each query contains two parameters . You need to find the mysterious number of the multiset formed by .
Input Format
- The first line contains an integer , the number of elements.
- The second line contains positive integers , indexed from .
- The third line contains an integer , the number of queries.
- Each of the next lines contains two integers .
Output Format
For each query, output one line with the corresponding answer.
5
1 2 4 9 10
5
1 1
1 2
1 3
1 4
1 5
2
4
8
8
8
Hint
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号