[Solution] Count the Trains Codeforces Solution
There are of independent carriages on the rails. The carriages are numbered from left to right from to . The carriages are not connected to each other. The carriages move to the left, so that the carriage with number moves ahead of all of them.
The -th carriage has its own engine, which can accelerate the carriage to km/h, but the carriage cannot go faster than the carriage in front of it. See example for explanation.
All carriages start moving to the left at the same time, and they naturally form trains. We will call trains — consecutive moving carriages having the same speed.
For example, we have carriages and array . Then the final speeds of the carriages will be . Respectively, of the train will be formed.
There are also messages saying that some engine has been corrupted:
- message "k d" means that the speed of the -th carriage has decreased by (that is, there has been a change in the maximum speed of the carriage ).
Messages arrive sequentially, the processing of the next message takes into account the changes from all previous messages.
After each message determine the number of formed trains.
The first line of input data contains a single integer () —the number of input test cases.
This is followed by descriptions of the test cases.
The first line of each test case is empty.
The second line of the test case contains two integers and () —the number of carriages and the number of messages to slow down the carriage, respectively.
The third line contains integers: () — the number means that the carriage with number can reach a speed of km/h.
The next lines contain two integers and (, ) —this is the message that the speed of the carriage with number has decreased by . In other words, there has been a change in its maximum speed . Note that at any time the speed of each carriage is non-negative. In other words, , where —is the sum of such that .
It is guaranteed that the sum of over all test cases does not exceed . Similarly, it is guaranteed that the sum of over all test cases does not exceed .
Print lines. On each line print the answer for the corresponding test case.
For each test case print numbers: the number of trains formed after each message.
No comments:
Post a Comment