#GD0000233. Tiêu diệt quái vật theo ngày (Yet Another Monster Killing Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tiêu diệt quái vật theo ngày (Yet Another Monster Killing Problem)
Yet Another Monster Killing Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A dungeon contains monsters in order, with strengths . You have heroes; hero has power and endurance .
Each day, select one hero to fight consecutive unbeaten monsters from the front. The hero defeats a monster only if its strength is at most the hero's power, and may defeat at most monsters per day. Any hero may be reused on another day, and defeated monsters do not return.
Find the minimum number of days to clear all monsters, or print -1 if impossible.
Input
- The first line contains .
- The next line contains monster strengths .
- The following line contains .
- The last lines contain each hero's .
Output
Print the minimum number of days, or -1 if completing the dungeon is impossible.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input
6
2 3 11 14 1 8
2
3 2
100 1
Output
5
Explanation
On day , hero defeats strengths . On days , hero defeats strengths separately. On day , hero defeats strength , and on day , hero defeats strength . Total: days.