PTSD
시간 제한1초메모리 제한1024 MB
병사 1번부터 n번을 여러 집단으로 나눌 때, 자기 집단에서 두 번째로 강한 PTSD 병사의 힘 값 합이 최대가 되도록 만든다.
문제
There are soldiers in JB kingdom, numbered as . The -th soldier has a power value of .
There is a tournament in the kingdom now. The soldiers need to be divided into several groups where each soldier belongs to exactly one group. Note that it's allowed for a group to contain only one single soldier. For some unknown reason, some soldiers have a disease called PTSD (post-traumatic stress disorder). The soldiers with PTSD don't like being the strongest soldier in their groups. Formally speaking, a soldier with PTSD will be upset if there is exactly one other soldier with a larger power value than him in his group.
JB, the king of JB kingdom, wants to maximize the sum of the power values of the soldiers who feel upset because of PTSD. You are asked to help him divide the soldiers.
입력
There are multiple test cases. The first line of the input contains a positive integer , indicating the number of test cases. For each test case:
The first line contains an integer (), indicating the number of soldiers.
The second line contains a string of length . It's guaranteed that only contains '0' and '1'. The -th character describes the -th soldier: If '1', the -th soldier has PTSD. Otherwise, the -th soldier doesn't have PTSD.
It's guaranteed that the sum of of all test cases doesn't exceed .
출력
For each test case, output one line containing an integer, indicating the maximum sum of power values of the upset soldiers.
힌트
For the first test case, a valid division is [1, 2], [3, 4], [5], which makes the -st soldier and the -rd soldier upset. [1, 2], [3, 5], [4] is also valid.
For the second test case, a valid division is [1, 2], [3, 4], [5, 6], [7, 8].
For the third test case, a valid division is [1, 3], [2, 4].
For the fourth test case, a valid division is [1, 2, 3, 4].