#K2041. Count Successfully Placed Advertisements
Count Successfully Placed Advertisements
Count Successfully Placed Advertisements
You are given a set of buildings with their heights and a number of billboards. An advertisement can only be placed on a building if:
- The height of the building is at least \(H_{min}\).
- No billboard blocking that building has a height greater than or equal to the building’s height. Specifically, a billboard placed on building i will block the advertisement if its height \(b \geq h_i\), where \(h_i\) is the height of building i.
You are given \(T\) test cases. For each test case, determine how many advertisements can be successfully placed.
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. For each test case, the input is formatted as follows:
n m H_min h1 h2 ... hn b1 idx1 b2 idx2 ... bm idxm
Here, \(n\) is the number of buildings, \(m\) is the number of billboards, and \(H_{min}\) is the minimum required height of a building to place an advertisement. The second line contains \(n\) integers representing the heights of the buildings. The next \(m\) lines each contain two integers: the first integer is the height of the billboard, and the second integer is the 0-based index of the building it blocks.
outputFormat
For each test case, output a single integer on a new line denoting the number of advertisements that can be placed successfully.
## sample1
5 3 100
120 150 180 90 105
130 0
170 2
160 1
2