306830: CF1257D. Yet Another Monster Killing Problem
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Yet Another Monster Killing Problem
题意翻译
你需要操作 $m$ 个英雄去打败 $n$ 只怪物,每个英雄的力量值为 $p_i$,可以打败 $s_i$ 只怪物;每只怪物的力量值为 $a_i$。 当新的一天开始时,你可以选择其中1个英雄去打怪(一个英雄可以选择多次)。若在之前已有k只怪物被打败,这个英雄将挑战第 $k+1$ 只怪物,此时有两种情况: 1、英雄力量 $<$ 怪物力量,则英雄撤退,这一天结束。 2、英雄力量 $\geqslant$ 怪物力量,怪物被打败。继续挑战下一只怪物。当 $n$ 只怪物全部被打败,或该英雄已打败的怪物数量为 $s_i$ 时,这一天结束。 你的任务是计算出打败所有怪物所需要的最小天数。 ------------ **输入格式:** 第一行包含整数 $T$,表示有 $T$ 组数据。 在每组数据中: 第一行一个整数,表示怪物数量 $n$ 第二行包含 $n$ 个整数,描述每只怪物的力量值 $a_i$ 第三行一个整数,表示英雄数量 $m$ 余下 $m$ 行中每行包含两个整数,分别是第 $i$ 个英雄的力量值 $p_i$ 与可打败怪物数 $s_i$ **输出格式:** 对于每组输入数据,输出一行,包含: 一个整数,表示打败所有怪物需要的最小天数 若无法打败所有怪物,输出 $-1$题目描述
You play a computer game. In this game, you lead a party of $ m $ heroes, and you have to clear a dungeon with $ n $ monsters. Each monster is characterized by its power $ a_i $ . Each hero is characterized by his power $ p_i $ and endurance $ s_i $ . The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day. When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated $ k $ monsters, the hero fights with the monster $ k + 1 $ ). When the hero fights the monster, there are two possible outcomes: - if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends; - otherwise, the monster is defeated. After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the $ i $ -th hero cannot defeat more than $ s_i $ monsters during each day), or if all monsters are defeated — otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends. Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.输入输出格式
输入格式
The first line contains one integer $ t $ ( $ 1 \le t \le 10^5 $ ) — the number of test cases. Then the test cases follow. The first line of each test case contains one integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of monsters in the dungeon. The second line contains $ n $ integers $ a_1 $ , $ a_2 $ , ..., $ a_n $ ( $ 1 \le a_i \le 10^9 $ ), where $ a_i $ is the power of the $ i $ -th monster. The third line contains one integer $ m $ ( $ 1 \le m \le 2 \cdot 10^5 $ ) — the number of heroes in your party. Then $ m $ lines follow, each describing a hero. Each line contains two integers $ p_i $ and $ s_i $ ( $ 1 \le p_i \le 10^9 $ , $ 1 \le s_i \le n $ ) — the power and the endurance of the $ i $ -th hero. It is guaranteed that the sum of $ n + m $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
For each test case print one integer — the minimum number of days you have to spend to defeat all of the monsters (or $ -1 $ if it is impossible).
输入输出样例
输入样例 #1
2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1
输出样例 #1
5
-1