#C6177. Maximum Fountain Overlap

    ID: 49908 Type: Default 1000ms 256MiB

Maximum Fountain Overlap

Maximum Fountain Overlap

You are given a number of water fountains arranged along a line. Each fountain is described by its position x and its radius r. The fountain waters an interval from x − r to x + r (inclusive). The task is to determine the maximum number of fountains that can simultaneously spray water on the same point.

In other words, for each test case, find the point on the line which is covered by the maximum number of fountain intervals and output that maximum count. Note that when a fountain's water range ends at a point, if another fountain starts at the same point, this transition is handled in such a way that they do not count as overlapping (i.e. the end event is processed before the start event).

The following diagram illustrates a sample scenario:

For a fountain at position x with radius r, the interval is given by:

\( [x - r,\; x + r] \)

Your goal is to compute the maximum overlap of such intervals for each test case.

inputFormat

The input is read from stdin and has the following format:

T
n₁
x₁ r₁
x₂ r₂
... (n₁ fountains)
n₂
x₁ r₁
x₂ r₂
... (n₂ fountains)
...

Where:

  • T is the number of test cases (T ≥ 3).
  • For each test case, the first line contains an integer n representing the number of fountains.
  • The next n lines each contain two integers separated by a space representing the position x and radius r of a fountain.
  • </p>

    outputFormat

    For each test case, output one integer on a new line, representing the maximum number of fountains that simultaneously spray water on some point.

    The output should be written to stdout.

    ## sample
    3
    3
    1 2
    4 1
    5 2
    4
    2 3
    6 1
    8 4
    12 2
    2
    3 1
    5 1
    
    2
    

    2 1

    </p>