#P9497. 「RiOI-2」weight
「RiOI-2」weight
Background
A fantasy castle sits among a small forest. This is the territory of Country E, and Little E is the king of Country E.
Trees are Country E's magic weapon to resist attacks. The taller the trees are, the better they can block the enemies' view.
However, as natural conditions get worse, Little E does not know what to do. What should he do?
Problem Description
Given an by matrix .
There are queries. In each query, a value is given. You may arbitrarily reorder each row of the matrix (or choose not to reorder it) to maximize the number of columns whose maximum value is not less than (that is, in that column, there is at least one number that is not less than ). Output this number of columns.
The queries are independent. In other words, you may reorder the matrix again before each query.
Input Format
The first line contains two positive integers .
Lines to each contain positive integers, representing the matrix .
Then follow lines, each containing one positive integer , representing a query.
Output Format
For each query, output one line containing one integer, representing the answer.
3 3
9 9 8
2 4 4
3 5 3
5
9
10
3
2
0
Hint
Sample Explanation
The original matrix is .
For the first query, the maximum value of each column is , all of which are not less than , so every column satisfies the condition and the answer is . Obviously, no matter how you reorder, it is impossible to exceed columns (because there are only columns in total), so the answer is .
Constraints
This problem uses bundled testdata.
| Score | |||
|---|---|---|---|
For all testdata, , , and .
Translated by ChatGPT 5