CF883J Renovation
Description
The mayor of the Berland city S sees the beauty differently than other city-dwellers. In particular, he does not understand at all, how antique houses can be nice-looking. So the mayor wants to demolish all ancient buildings in the city.
The city S is going to host the football championship very soon. In order to make the city beautiful, every month the Berland government provides mayor a money tranche. The money has to be spent on ancient buildings renovation.
There are $ n $ months before the championship and the $ i $ -th month tranche equals to $ a_{i} $ burles. The city S has $ m $ antique buildings and the renovation cost of the $ j $ -th building is $ b_{j} $ burles.
The mayor has his own plans for spending the money. As he doesn't like antique buildings he wants to demolish as much of them as possible. For the $ j $ -th building he calculated its demolishing cost $ p_{j} $ .
The mayor decided to act according to the following plan.
Each month he chooses several (possibly zero) of $ m $ buildings to demolish in such a way that renovation cost of each of them separately is not greater than the money tranche $ a_{i} $ of this month ( $ b_{j}
Input Format
The first line of the input contains two integers $ n $ and $ m $ $ (1
Output Format
Output single integer — the maximal number of buildings the mayor can demolish.
Explanation/Hint
In the third example the mayor acts as follows.
In the first month he obtains $ 6 $ burles tranche and demolishes buildings $ #2 $ (renovation cost $ 6 $ , demolishing cost $ 4 $ ) and $ #4 $ (renovation cost $ 5 $ , demolishing cost $ 2 $ ). He spends all the money on it.
After getting the second month tranche of $ 3 $ burles, the mayor selects only building $ #1 $ (renovation cost $ 3 $ , demolishing cost $ 1 $ ) for demolishing. As a result, he saves $ 2 $ burles for the next months.
In the third month he gets $ 2 $ burle tranche, but decides not to demolish any buildings at all. As a result, he has $ 2+2=4 $ burles in the bank.
This reserve will be spent on the fourth month together with the $ 4 $ -th tranche for demolishing of houses $ #3 $ and $ #5 $ (renovation cost is $ 4 $ for each, demolishing costs are $ 3 $ and $ 5 $ correspondingly). After this month his budget is empty.
Finally, after getting the last tranche of $ 3 $ burles, the mayor demolishes building $ #6 $ (renovation cost $ 2 $ , demolishing cost $ 3 $ ).
As it can be seen, he demolished all $ 6 $ buildings.