GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 11 October 2022

[Solution] Sending a Sequence Over the Network Codeforces Solution



E. Sending a Sequence Over the Network
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The sequence a is sent over the network as follows:

  1. sequence a is split into segments (each element of the sequence belongs to exactly one segment, each segment is a group of consecutive elements of sequence);
  2. for each segment, its length is written next to it, either to the left of it or to the right of it;
  3. the resulting sequence b is sent over the network.

For example, we needed to send the sequence a=[1,2,3,1,2,3]. Suppose it was split into segments as follows: [1]+[2,3,1]+[2,3]. Then we could have the following sequences:

  • b=[1,1,3,2,3,1,2,3,2],
  • b=[1,1,3,2,3,1,2,2,3],
  • b=[1,1,2,3,1,3,2,2,3],
  • b=[1,1,2,3,1,3,2,3,2].

If a different segmentation had been used, the sent sequence might have been different.

The sequence b is given. Could the sequence b be sent over the network? In other words, is there such a sequence a that converting a to send it over the network could result in a sequence b?

Input

The first line of input data contains a single integer t (1t104) — the number of test cases.

Each test case consists of two lines.

The first line of the test case contains an integer n (1n2105) — the size of the sequence b.

The second line of test case contains n integers b1,b2,,bn (1bi109) — the sequence b itself.

It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output

For each test case print on a separate line:

  • YES if sequence b could be sent over the network, that is, if sequence b could be obtained from some sequence a to send a over the network.
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEsyesYes and YES will be recognized as positive response).

No comments:

Post a Comment