Observer.AIOA #1
Choose the Best Flask
估计中等可在线判题
Choose one flask type that can serve all orders and minimizes the total waste, i.e. marked capacity minus order volume; break ties by the smallest type index.
The standard input/output format and supplementary bounds on this site are as defined in this problem statement.
输入格式
n (1≤n≤1000); the next line contains n order volumes (1..10^9); then f (1≤f≤1000), followed by one line per flask type: first the number of markings, then the markings in ascending order. The total number of markings is ≤2×10^5.
输出格式
Output the 0-based flask type index; if no type can serve all orders, output -1.
样例 1
输入:
4
4 6 6 7
3
3
3 5 7
3
6 8 9
3
3 5 6
输出:
0
样例 2
输入:
2
10 11
1
2
1 5
输出:
-1
样例 3
输入:
3
12 10 9
2
1
3
5
2 2 3 11 17
输出:
1