Bad Doctor
Time limit3sMemory limit512 MB
Each doctor prescribes a set of medicines over a day interval; ignoring one doctor, compute the total cost of distinct medicines needed per day summed over all days.
- Level
Hard8 of 10
- Topics
- Segment tree, Sorting, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Alex got sick. He went to a clinic and visited doctors. The -th doctor said that starting with day and ending with day , Alex must take medicines: , one pill a day of each. Medicines are numbered from 1 to .
Of course, if several doctors tell Alex to take the same medicine on the same day, he takes only one pill of that medicine that day. At least, that is how people act in real life.
One pill of medicine costs roubles. But Alex has a doubt: rumors say that one of the doctors in the clinic is really bad. He does not know which doctor is bad, but he decided to ignore this doctor's prescription.
Your task is to find numbers : how much money Alex will spend on pills if the -th doctor is bad.
Input
The first line contains two integers and : the number of doctors and the number of medicines (, ).
The second line contains integers : the cost of one pill of the -th medicine ().
Each of the next lines describes a doctor. The -th of them starts with three integers : the start and end days of the -th doctor's prescription and the number of medicines he told Alex to take (, ). Then follow distinct integers , each from 1 to : the medicines in the prescription.
The sum of all in the input does not exceed .
Output
Output integers : how much money Alex will spend on pills if he ignores the -th doctor's prescription.