#C5940. Arranging Artists
Arranging Artists
Arranging Artists
Alex is organizing a photo shoot with artists who are either Singers or Dancers. The arrangement is represented as a sequence of N binary integers where 1
denotes a Singer and 0
denotes a Dancer. Although Alex originally wanted all Singers on one side and Dancers on the other, the process used ends up with all Dancers grouped to the left and all Singers to the right.
The process is as follows: In each minute, for every adjacent pair, if the left artist is a Singer and the right artist is a Dancer, they swap positions. In other words, every occurrence of a pair that satisfies
$$arr[i]=1\text{ and }arr[i+1]=0$$
will swap to become 0 1
in that minute. This operation is applied sequentially from left to right, and all eligible swaps occur within the same minute. The process repeats until no more swaps can be made.
Your task is to compute the total number of minutes required for the line to reach a state where no such adjacent pair exists.
inputFormat
The input is given via standard input (stdin) and has the following format:
T N a1 a2 ... aN ...
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N representing the number of artists.
- The next line contains N space-separated integers (each either 0 or 1) representing the arrangement of the dancers and singers. </p>
outputFormat
For each test case, output a single integer on a new line representing the number of minutes required until no more swaps can be performed. The output should be sent to standard output (stdout).
## sample2
6
1 0 1 0 1 0
4
1 0 1 0
3
2
</p>