#CTR0014. clothes
clothes
Description
jiangys is going hiking and needs to pack some clothes.
He has clothes, and the -th one keeps him warm by points. He can choose to bring clothes to meet the weather for the next days.
Each day has different rules:
If , the total warmth of the clothes he wears that day must be at least .
If , the total warmth must not exceed .
Each day, he can pick some of the clothes he packed(but must wear, so at least one).
What's the smallest number of clothes he needs to bring to meet all day's rules? If it's impossible, output .
Input Format
First line: , number of clothes.
Second line: , warmth of each clothes.
Third line: , number of days.
Next lines: and , rules for each day.
$1 \leq n \leq 3 , 1 \leq a_i \leq 2 \times 10^5, 1 \leq m \leq 100, 1 \leq t_i \leq 2,1 \leq x_i \leq 10^9$.
Output Format
The smallest number of clothes he needs to bring, or if impossible.
Sample Input #1
3
2 3 5
1
1 10
Sample Output #1
3
Sample Input #2
3
2 3 5
2
1 5
2 2
Sample Output #2
2
Sample Input #3
3
7 11 13
2
1 24
2 7
Sample Output #3
3
Sample Input #4
2
17 19
2
1 16
2 18
Sample Output #4
1
Sample Input #5
3
2 11 19
2
1 1000000000
2 1
Sample Output #4
-1
相关
在下列比赛中: