Submitting Assignments
Time limit1sMemory limit1024 MB
Given N knowledge pieces that each expire after a set number of days and M problems needing certain pieces, find the fewest studies needed to solve all problems in some order.
- Level
Medium5 of 10
- Topics
- Brute force, Greedy, Simulation
- Solved
- No attempts yet
Problem
Seonghyeon's course covers pieces of knowledge, numbered from 1 to .
Seonghyeon must solve all problems and submit them. Solving one problem takes one day, and Seonghyeon chooses the order of the problems. So Seonghyeon solves exactly one problem on each of day 1, day 2, , day .
To solve problem , Seonghyeon needs pieces of knowledge: , , , .
Knowledge fades over time. If Seonghyeon studies piece on day , then on day Seonghyeon has forgotten piece . On that day Seonghyeon may need to study it again. Seonghyeon may learn several pieces of knowledge on the same day.
Find the minimum number of times Seonghyeon must study pieces of knowledge so that all problems are solved.
Input
The first line contains and , separated by a space.
The second line contains , , , , separated by spaces. is the number of days after which piece is forgotten after it is studied.
Each of the next lines contains , followed by the integers , , , , separated by spaces. is the number of a piece of knowledge needed to solve problem .
Output
Print the minimum number of times Seonghyeon must study pieces of knowledge.
Constraints
- Every is an integer.
- For every , holds.