We Need Masks
Time limit3sMemory limit1024 MB
Each citizen accepts mask prices in a range [L, R], each store sells X masks at price P, and we must match as many citizens to masks as possible.
Problem
After COVID-19 broke out, the need for masks began to grow. Without a mask, daily life is difficult, so you must always keep masks on hand.
As demand for masks rose, mask prices that had been uniform began to differ from store to store. Because the prices varied, it became hard for every citizen of city A to get a mask. As a civil servant of city A, you asked the store owners to make mask prices uniform in order to resolve the situation, but the store owners ignored you, as expected.
Judging that persuading the store owners is difficult, you changed your plan to letting as many citizens as possible get masks. You found out the range of money each citizen of city A can spend on a mask, and the price and quantity of the masks sold at each store in city A. Each citizen can buy at most one mask. Based on this information, let as many citizens as possible get masks.
Input
The first line gives , the number of citizens of city A, and , the number of stores in city A. ()
Lines 2 through give and , the range of money the -th citizen of city A can spend on a mask. That is, the price of a mask the -th citizen of city A can buy is at least and at most . ()
Lines through give , the price of the masks sold by the -th store in city A, and , the number of masks. (, )
All of , , , and are integers.
Output
Print the number of citizens who bought a mask when as many citizens as possible have bought one.