ones-and-zeros-and-minus-ones

Level 3 

Given an array a of size n containing only 0,-1,and 1,

x = number of 1's in a[l,r] (in subarray from l to r)

y = number of -1's in a[l,r] (in subarray from l to r)

For any sub array [l,r] function f is defined as follows

if(y == 0)

f([l,r]) = 0;

else

f([l,r]) = x / y;

Your goal is determine the maximum value of the function f.
Print the maximum value in most reduced fraction form i.e. p/q where gcd(p,q) = 1.

Input Format:

First line contains T, the number of test cases (1 ≤ T ≤ 10)

For each test case line,first line contains n, the size of array (1 ≤ n ≤ 10^5)

Second line of each test case contains n space separated integers. (a[i] /belongs to/ {-1,0,1})

Output Format:

Print maximum value of function f in reduced fraction form without any spaces for each test case in a single line

Author : Sumeet Varma

SAMPLE INPUT
2
2
1 1
3
1 1 -1

SAMPLE OUTPUT
0/1
2/1

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=int(input())
for i in range(t):
	n=int(input())
	num=list(map(int,input().split()))
	l=0
	r=0
	f=0
	ma=0
	for j in num:
		if j==1:
			r+=1
		elif j==-1:
			f=1
			l=r
			r=0
		if l+r>ma:
			ma=l+r
	if f==0:
		print('0/1')
	else :
		print(str(ma)+'/1')


t = int(input())

for i in range(0, t):
	n = input()
	inp = input()
	inp  = inp.split('-1')
	
	count = []
	for st in inp:
		count.append(st.count('1'))
	
	max = 0
	
	for j in range(0, len(count)-1):
		if count[j] + count[j+1] > max:
			max = count[j] + count[j+1]
	
	if max == 0:
		print('0/1')
	else:
		print(str(max)+'/1')


t=int(input())
for _ in range(t):
	n=int(input())
	l=input().split()
	l=list(map(int,l))
	x=0
	y=0
	max=0
	value=False
	for a in l:
		if a==1:
			x+=1
		elif a==-1:
			value=True
			if x+y>max:
				max=x+y
			y=x
			x=0
	if x+y>max and value:
		max=x+y
	print("%d/1"%(max))
			 
	
		  


test = eval(input())
for i in range(test) :
	n = eval(input())
	a = []
	a = list(map(int, input().split()))
	o = a.count(1)
	mo = a.count(-1)
	if mo == 0 :
		print("0/1")
		continue
	elif mo == 1 :
		print(str(o)+"/1")
		continue
	elif mo == n :
		print("0/1")
		continue
	b = [0]
	for j in range(n) :
		if a[j] == 1 :
			b[-1] += 1
		elif a[j] == -1 :
			b.append(0)
	m = 0
	for j in range(mo-1) :
		if m < b[j] + b[j+1] :
			m = b[j] + b[j+1]
	print(str(m)+"/1")