BestCoder Round #66 1002
GTW likes gt
Long long ago, there were nn adorkable GT. Divided into two groups, they were playing games together, forming a column. The i−th GT would randomly get a value of ability bi. At the i−th second, the i−th GT would annihilate GTs who are in front of him, whose group differs from his, and whose value of ability is less than his.
In order to make the game more interesting, GTW, the leader of those GTs, would emit energy for mm times, of which the i−th time of emitting energy is ci. After the ci second, b1,b2,...,bci would all be added 1.
GTW wanted to know how many GTs would survive after the n−th second.
The first line of the input file contains an integerT(≤5), which indicates the number of test cases.
For each test case, there are n+m+1 lines in the input file.
The first line of each test case contains 2 integers nn and mm, which indicate the number of GTs and the number of emitting energy, respectively.(1≤n,m≤50000)
In the following nn lines, the i−th line contains two integers ai and bi, which indicate the group of the i−th GT and his value of ability, respectively. (0≤ai≤1,1≤bi≤10^6)
In the following mm lines, the i−th line contains an integer ci, which indicates the time of emitting energy for i−th time.
There should be exactly T lines in the output file.
The i−th line should contain exactly an integer, which indicates the number of GTs who survive.
1 4 3 0 3 1 2 0 3 1 1 1 3 4
3