CF BUDDY
← Problems·

1710B · Rain

2100 · binary search, brute force, data structures

Problem: You are the owner of a harvesting field which can be modeled as an infinite line, whose positions are identified by integers.

It will rain for the next nn days. On the ii-th day, the rain will be centered at position xix_i and it will have intensity pip_i. Due to these rains, some rainfall will accumulate; let aja_j be the amount of rainfall accumulated at integer position jj. Initially aja_j is 00, and it will increase by max(0,pixij)\max(0,p_i-|x_i-j|) after the ii-th day's rain.

A flood will hit your field if, at any moment, there is a position jj with accumulated rainfall aj>ma_j>m.

You can use a magical spell to erase exactly one day's rain, i.e., setting pi=0p_i=0. For each ii from 11 to nn, check whether in case of erasing the ii-th day's rain there is no flood.

Input Format: Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \leq t \leq 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n21051 \leq n \leq 2 \cdot 10^5, 1m1091 \leq m \leq 10^9) — the number of rainy days and the maximal accumulated rainfall with no flood occurring.

Then nn lines follow. The ii-th of these lines contains two integers xix_i and pip_i (1xi,pi1091 \leq x_i,p_i \leq 10^9) — the position and intensity of the ii-th day's rain.

The sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output a binary string ss length of nn. The ii-th character of ss is 1 if after erasing the ii-th day's rain there is no flood, while it is 0, if after erasing the ii-th day's rain the flood still happens.

Note: In the first test case, if we do not use the spell, the accumulated rainfall distribution will be like this:

If we erase the third day's rain, the flood is avoided and the accumulated rainfall distribution looks like this:

In the second test case, since initially the flood will not happen, we can erase any day's rain.

In the third test case, there is no way to avoid the flood.

Sample Cases

Case 1

Input

4
3 6
1 5
5 5
3 4
2 3
1 3
5 2
2 5
1 6
10 6
6 12
4 5
1 6
12 5
5 5
9 7
8 3

Output

001
11
00
100110

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback