#C4691. Maximum Concurrent Requests

    ID: 48257 Type: Default 1000ms 256MiB

Maximum Concurrent Requests

Maximum Concurrent Requests

You are given a list of server request events. Each event is represented as a tuple \((t, type)\), where \(t\) denotes the time of the event and \(type\) indicates the event: a value of \(1\) means a request arrival, and \(-1\) means a request completion.

Your task is to determine the maximum number of concurrent requests handled by the server at any moment in time.

Details:

  • If two events occur at the same time, the arrival event \((1)\) should be processed before the completion event \((-1)\). This can be achieved by sorting the events by time in ascending order and, if times are equal, sorting by \(type\) in descending order (i.e. \(1\) before \(-1\)).
  • You can simulate the process as a sweep line algorithm: increase a counter for each arrival and decrease it for each completion, tracking the maximum counter value.

Good luck!

inputFormat

The input is read from standard input (stdin) and is structured as follows:

  1. The first line contains an integer \(T\) representing the number of test cases.
  2. For each test case:
    • The first line contains an integer \(N\) denoting the number of requests.
    • The next line contains \(N\) requests. Each request is provided in the format \((t, type)\) and the requests are separated by a space.

The input is guaranteed to be well-formed.

outputFormat

For each test case, output a single integer representing the maximum number of concurrent requests processed by the server. Each result should be printed on a separate line to standard output (stdout).

## sample
1
1
(1, 1)
1