You are lost deep in the forest. The only thing that is still accompanying you is your stoat. It has an initial attack of 11. It is your only Beast at the beginning.
A single path revealed itself before you. On the path are n event marks. Every event mark falls into one of the following:
When you walk through the winding road, the event marks will be triggered in order. Find out the maximum average of attack for your Beasts you can achieve after all event marks are completed.
Input
There are multiple test cases. The first line of the input contains an integer T indicating the number of test cases. For each test case:
The first line contains one integer n (1≤n≤106) indicating the number of event marks.
The second line contains nintegers a1,a2,⋯,an1,2,⋯, (−1≤ai≤1) where ai indicates the type of the i-th event mark: 11 means a Card Choice, −1−1 means a Mysterious Stone and 00 means a Fork in the Road.
It's guaranteed that the sum of n over all test cases does not exceed 106106.
Output
For each test case output one line.
If it is impossible to complete all event marks, output one integer −1−1.
Otherwise it can be proven that the answer is a rational number p′q Output two integers p and qwhere pq is the simplest fraction representation of p′q
pqis the simplest fraction representation of p′q if pq=p′q′ and the greatest common divisor of p and q is 11.
一个集合,初始为{1},给一个序列,序列由1,0,-1组成,当遇到1时,集合加一个元素1,遇到-1时,让集合两个元素合成一个,遇到0时,可以选择进行1或-1的操作。
我们可以看到当遇到0时,如果集合个数》=2,我们选择-1比选择1更合算,当《2时,选择转化成1,并且要记录转化成-1的0的个数,当后边遇到-1,并且集合个数为1时,可以让之前转化成-1的0转变为1,来扩大集合个数,如果没有0可以由1转化成-1,输出-1。
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include