#P9497. 「RiOI-2」weight

    ID: 10143 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>贪心二分洛谷原创O2优化排序洛谷月赛

「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 nn by nn matrix aa.

There are qq queries. In each query, a value vv 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 vv (that is, in that column, there is at least one number that is not less than vv). 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 n,qn, q.

Lines 22 to n+1n + 1 each contain nn positive integers, representing the matrix aa.

Then follow qq lines, each containing one positive integer vv, 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 [998244353]\begin{bmatrix}9&9&8\\2&4&4\\3&5&3\end{bmatrix}.

For the first query, the maximum value of each column is 9,9,89, 9, 8, all of which are not less than v=5v = 5, so every column satisfies the condition and the answer is 33. Obviously, no matter how you reorder, it is impossible to exceed 33 columns (because there are only 33 columns in total), so the answer is 33.

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} Score nn \leq qq \leq
00 1010 33 1010
11 4040 100100 10310^3
22 5050 10310^3 5×1055\times 10^5

For all testdata, 1n1031 \leq n \leq 10^3, 1q5×1051 \leq q \leq 5\times 10^5, and 1ai,j,v1091 \leq a_{i,j}, v \leq 10^9.

Translated by ChatGPT 5