传统题 1000ms 256MiB

clothes

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Description

jiangys is going hiking and needs to pack some clothes.

He has nn clothes, and the ii-th one keeps him warm by aia_i points. He can choose to bring 1n1\sim n clothes to meet the weather for the next mm days.

Each day has different rules:

If ti=1t_i = 1, the total warmth of the clothes he wears that day must be at least xix_i.

If ti=2t_i = 2, the total warmth must not exceed xix_i.

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 1-1.

Input Format

First line: nn, number of clothes.

Second line: a1ana_1 \sim a_n, warmth of each clothes.

Third line: mm, number of days.

Next mm lines: tit_i and xix_i, 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 1-1 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

2025XCPC集训队&&算法培训 — 综合训练(一)

未参加
状态
已结束
规则
ACM/ICPC
题目
5
开始于
2025-8-22 19:00
结束于
2025-8-22 22:00
持续时间
3 小时
主持人
参赛人数
21