Chef recently solved his first problem on CodeChef. The problem he solved has N test cases. He gets a score for his submission according to the following rules:

1) If Chef’s code passes all the N test cases, he gets 100 points.

2) If Chef’s code does not pass all the test cases, but passes all the first M\;(M < N) test cases, he gets K\;(K < 100) points.

3) If the conditions 1 and 2 are not satisfied, Chef does not get any points (i.e his score remains at 0 points).

You are given a binary array A_{1}, A_{2}, \dots, A_{N} of length N, where A_{i} = 1 denotes Chef's code passed the i^{th} test case, A_{i} = 0 denotes otherwise. You are also given the two integers M, K. Can you find how many points does Chef get?

------ Input Format ------ 

- First line will contain T, number of testcases. Then the testcases follow.
- The first line of each test case contains three space-separated integers N, M, K.
- The second line contains N space-separated integer A_{1}, A_{2},\dots, A_{N}.

------ Output Format ------ 

For each testcase, output in a single line the score of Chef.

------ Constraints ------ 

$1 ≤ T ≤ 100$
$2 ≤ N ≤ 100$
$1 ≤ M < N$
$1 ≤ K < 100$
$0 ≤ A_{i} ≤ 1$

----- Sample Input 1 ------ 
4
4 2 50
1 0 1 1
3 2 50
1 1 0
4 2 50
1 1 1 1
5 3 30
1 1 0 1 1

----- Sample Output 1 ------ 
0
50
100
0

----- explanation 1 ------ 
Test case $1$: Chef's code neither passes all $4$ test cases nor passes the first $2$ test cases. Hence he does not get any points.

Test case $2$: Chef's code does not pass all $3$ test cases, but passes the first $2$ test cases. Hence he gets $50$ points.

Test case $3$: Chef's code passes all the $4$ test cases. Hence he gets $100$ points.

Source: codechef | Difficulty: EASY
Tags: Mathematics

Data structures

Implementation

Complete search


Solutions:
T = int(input())
temp = 0
flag = 0
for i in range(T):
	(N, M, K) = map(int, input().split())
	A = list(map(int, input().strip().split()))[:N]
	for j in range(N):
		if A[j] == 0:
			temp = 1
			break
		else:
			pass
	if N == M or temp == 0:
		print('100')
	else:
		temp = 0
		for j in range(M):
			if A[j] == 0:
				flag = 1
				break
			else:
				pass
		if flag == 1:
			print('0')
			flag = 0
		else:
			print(K)


t = int(input())
for i in range(t):
	ind = -1
	l = list(map(int, input().split(' ')))
	ins = list(map(int, input().split(' ')))
	if 0 in ins:
		ind = ins.index(0)
	if 0 not in ins:
		print(100)
	elif ind >= 0 and ind < l[1]:
		print(0)
	else:
		print(l[2])


for i in range(int(input())):
	a = list(map(int, input().split()))
	l = list(map(int, input().split()))
	c = 0
	for i in l:
		if i == 1:
			c += 1
		else:
			break
	if c == a[0]:
		print(100)
	elif c >= a[1]:
		print(a[2])
	else:
		print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	count = arr.count(1)
	if count == n:
		print(100)
	else:
		add = 0
		for i in range(m):
			if arr[i] == 1:
				add += 1
		if add == m:
			print(k)
		else:
			print(0)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	if set(l) == {1}:
		ctr = 100
	else:
		for i in range(b):
			if l[i] == 0:
				ctr = 0
				break
			else:
				ctr = c
	print(ctr)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	count_1 = arr.count(1)
	if count_1 == len(arr):
		print(100)
	else:
		count = 0
		for i in range(m):
			if arr[i] == 1:
				count += 1
		if count == m:
			print(k)
		else:
			print(0)


def sol(total, req, points, arr):
	if not 0 in arr:
		return 100
	check = arr[:req]
	if not 0 in check:
		return points
	else:
		return 0
for i in range(int(input())):
	(total, req, points) = map(int, input().split())
	arr = input().split()
	arr = [int(i) for i in arr]
	print(sol(total, req, points, arr))


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if a.count(1) == n:
		print('100')
	else:
		for i in range(m):
			if a[i] != 1:
				print('0')
				break
		else:
			print(k)


for t in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = [int(i) for i in input().split()]
	if max(l) == min(l) and max(l) != 0:
		print(100)
	else:
		d = l[:b]
		if max(d) == min(d) and max(d) != 0:
			print(c)
		else:
			print(0)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	z = a.count(1)
	if z == n:
		print('100')
	else:
		z = 0
		for j in range(m):
			if a[j] == 1:
				z = z + 1
		if z == m:
			print(k)
		else:
			print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	flag = 0
	for i in range(m):
		if a[i] == 0:
			flag = 1
	if a.count(1) == n:
		print(100)
	elif a.count(1) < n and flag == 0:
		print(k)
	elif flag == 1:
		print(0)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	r = l.count(1)
	l = l[0:m]
	r1 = l.count(1)
	if r == n:
		print(100)
	elif r1 == m:
		print(k)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	j = l.count(1)
	l = l[0:m]
	j1 = l.count(1)
	if j == n:
		print(100)
	elif j1 == m:
		print(k)
	else:
		print(0)


t = int(input())
while t > 0:
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	tc = l.count(1)
	l = l[0:m]
	tc1 = l.count(1)
	if tc == n:
		print(100)
	elif tc1 == m:
		print(k)
	else:
		print(0)
	t = t - 1


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))

	def f(x):
		s = 0
		for i in range(x):
			s = l[i] + s
		return s
	if f(n) == n:
		print(100)
	elif f(m) == m and f(n) < n:
		print(k)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	c = 0
	for i in range(m):
		if a[i] == 1:
			c += 1
		else:
			break
	if c == m and str(a).count('1') == n:
		print(100)
	elif c == m:
		print(k)
	else:
		print(0)


for cases in range(int(input())):
	(test, passed, points) = map(int, input().split())
	test_cases = list(map(int, input().split()))
	if sum(test_cases) == test:
		print(100)
	else:
		index = test_cases.index(0) + 1
		if index > passed:
			print(points)
		else:
			print(0)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	one_count = 0
	for i in range(n):
		if arr[i] == 0:
			break
		else:
			one_count += 1
	if one_count < m:
		print(0)
	elif one_count != n:
		print(k)
	else:
		print(100)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	b = 0
	for i in range(m):
		b = b + a[i]
	if s == n:
		print('100')
	elif b == m:
		print(k)
	else:
		print('0')


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = a.copy()
	b.sort()
	h = True
	if b[0] == 1:
		print(100)
	else:
		for d in range(m):
			if a[d] == 0:
				print(0)
				h = False
				break
		if h == True:
			print(k)


t = int(input())
for i in range(t):
	(N, M, K) = map(int, input().split())
	x = list(map(int, input().split()))
	count = 0
	for i in x:
		if i == 0:
			count = x.index(i) + 1
			break
	if count == 0:
		print(100)
	elif count <= M:
		print(0)
	else:
		print(K)


count = int(input())
for _ in range(count):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = 0
	for a in range(n):
		if arr[a] == 1:
			c += 1
		else:
			break
	if c == n:
		print(100)
	elif c >= m:
		print(k)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = 0
	c = a.count(1)
	if c == n and b == m:
		print('100')
	for j in range(m):
		if a[j] == 1:
			b += 1
	if c == n and b == m:
		print('100')
	elif b == m:
		print(k)
	else:
		print('0')
	b = 0


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	x = arr[0:m]
	if arr.count(1) == n:
		print(100)
	elif x.count(1) == m:
		print(k)
	else:
		print(0)


for x in range(int(input())):
	(N, M, K) = map(int, input().split())
	l = list(map(int, input().split()))
	if l.count(0) == 0:
		print(100)
		continue
	else:
		l1 = l[:M]
		if l1.count(0) == 0:
			print(K)
		else:
			print(0)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	one = arr.count(1)
	if one == n:
		print(100)
		continue
	one = 0
	for j in range(m):
		if arr[j] == 1:
			one += 1
	if one == m:
		print(k)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) == n:
		print('100')
	else:
		x = 0
		for i in range(m):
			if a[i] == 1:
				x += 1
		if x == m:
			print(k)
		else:
			print('0')


t = int(input())
for x in range(t):
	b = [int(c) for c in input().split()]
	a = [int(c) for c in input().split()]
	if sum(a) == b[0]:
		print(100)
	elif sum(a[:b[1]]) == b[1]:
		print(b[2])
	else:
		print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) == n:
		print(100)
	elif sum(a[:m]) == m:
		print(k)
	else:
		print(0)


for _ in range(int(input())):
	(a, b, c) = map(int, input().split())
	n = list(map(int, input().split()))
	z = n.count(1)
	if z == a:
		print(100)
	else:
		z = 0
		for j in range(b):
			if n[j] == 1:
				z = z + 1
		if z == b:
			print(c)
		else:
			print(0)


n = int(input())
for i in range(n):
	(a, b, c) = map(int, input().split(' '))
	d = list(map(int, input().split(' ')))
	e = d.count(1)
	if e == a:
		print('100')
	else:
		count = 0
		for j in range(b):
			if d[j] == 1:
				count += 1
		if count == b:
			print(c)
		else:
			print(0)


t = int(input())
while t:
	(n, m, k) = map(int, input().split())
	N = list(map(int, input().split()))
	c = 0
	z = N.count(1)
	if z == n:
		print(100)
	else:
		for i in range(m):
			if N[i] == 1:
				c += 1
		if c == m:
			print(k)
		else:
			print(0)
	t -= 1


from collections import Counter

def test():
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if not 0 in l:
		print(100)
	elif sum(l[:m]) == m:
		print(k)
	else:
		print(0)
t = int(input())
for _ in range(t):
	test()


t = int(input())
for _ in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	(mpass, npass) = (True, True)
	score = 0
	for i in range(m):
		if arr[i] == 0:
			mpass = False
			break
	if mpass:
		score = k
		for i in range(m, n):
			if arr[i] == 0:
				npass = False
				break
		if npass:
			score = 100
	print(score)


for i in range(int(input())):
	(a, b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	co = 0
	for j in l:
		if j == 1:
			co += 1
		if j == 0:
			break
	if co == a:
		print(100)
	elif co >= b:
		print(c)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	s1 = input().split()
	s2 = list(map(int, s1))
	flag = True
	count = 0
	if s2.count(1) == n:
		print(100)
	else:
		for i in range(len(s1)):
			if s2[i] == 0:
				count = 0
				print(0)
				break
			else:
				count = count + 1
				if count == m:
					flag = False
					break
		if flag == False:
			print(k)


for _ in range(int(input())):
	(n, m, k) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	cnt = 0
	found = False
	for i in arr:
		if i == 1 and (not found):
			cnt += 1
		elif i == 0:
			found = True
			break
	if cnt == n:
		print(100)
	elif cnt >= m:
		print(k)
	else:
		print(0)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	nota = 0
	for i in range(len(a)):
		if a[i] == 0:
			nota = k if i >= m else 0
			break
	else:
		nota = 100
	print(nota)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if l.count(1) == n:
		print(100)
	elif l[:m].count(1) == m:
		print(k)
	else:
		print(0)


t = int(input())
for i in range(t):
	(n, m, k) = list(map(int, input().split()))
	li = list(map(int, input().split()[:n]))
	c = 0
	for i in range(m):
		if li[i] == 1:
			c = c + 1
		else:
			c = 0
			break
	if c != 0:
		for i in range(len(li) - m):
			if li[i + m] == 1:
				c += 1
	if c == len(li):
		print(100)
	elif c != 0:
		print(k)
	else:
		print(0)


for i in range(0, int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if b.count(1) == a[0]:
		print(100)
	else:
		t = 0
		for j in range(len(b)):
			if b[j] == 1:
				t = t + 1
				continue
			else:
				break
		if t >= a[1]:
			print(a[2])
		else:
			print(0)


t = int(input())
for i in range(t):
	c = 0
	b = 0
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] == 1:
			c += 1
	for i in range(m):
		if l[i] == 1:
			b += 1
	if c == n:
		print(100)
	elif b == m:
		print(k)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = list(input().split())
	i = 0
	while i < n and a[i] == '1':
		i += 1
	if i == n:
		print(100)
	elif i >= m:
		print(k)
	else:
		print(0)


t = int(input())
while t > 0:
	(n, m, k) = input().split(' ')
	l = input().split(' ')
	n = int(n)
	m = int(m)
	k = int(k)
	s = 0
	c = 1
	if l.count('1') == n:
		s = 100
	else:
		s = k
		for i in range(0, m):
			if l[i] == '0':
				c = 0
				s = 0
				break
	print(s)
	t -= 1


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	li = list(map(int, input().split()))
	a = li.copy()
	a.sort()
	f = True
	if a[0] == 1:
		print(100)
	else:
		for i in range(m):
			if li[i] == 0:
				print(0)
				f = False
				break
		if f == True:
			print(k)


for i in range(int(input())):
	(N, M, K) = map(int, input().split())
	arr = list(map(int, input().split()))
	b = arr.copy()
	b.sort()
	h = True
	if b[0] == 1:
		print(100)
	else:
		for i in range(M):
			if arr[i] == 0:
				print(0)
				h = False
				break
		if h == True:
			print(K)


for t in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = True
	if a.count(1) == n:
		print(100)
	else:
		for i in range(m):
			if a[i] != 1:
				flag = False
		if flag:
			print(k)
		else:
			print(0)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = [int(i) for i in input().split()]
	if l.count(0) == 0:
		print(100)
	elif sum(l[:m]) == m:
		print(k)
	else:
		print(0)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	one = l.count(1)
	zero = l.count(0)
	c = 0
	if zero == 0:
		print(100)
	else:
		for j in range(m):
			if l[j] == 1:
				c = c + 1
		if c == m:
			print(k)
		else:
			print(0)


for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	A = input().split()
	(score, c, d) = (0, True, True)
	for i in range(N):
		if A[i] == '1':
			pass
		else:
			c = False
			break
	if c:
		score = 100
	else:
		for i in range(M):
			if A[i] == '1':
				pass
			else:
				d = False
				break
		if d:
			score = K
	print(score)


a = int(input())
for i in range(1, a + 1):
	count = 0
	(p, q, r) = map(int, input().split())
	n = list(map(int, input().split()))
	for j in range(q):
		if n[j] == 1:
			count = count + 1
	if n.count(1) == p:
		print('100')
	elif count == q:
		print(r)
	else:
		print('0')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	p = list(map(int, input().split()))
	if 0 in p:
		s = p.index(0)
	else:
		s = -1
	if s == -1:
		print(100)
	elif s + 1 > m:
		print(k)
	else:
		print(0)


T = int(input())
for t in range(0, T):
	(N, M, K) = map(int, input().split())
	A = list(map(int, input().split()))
	any_failed = False
	first_consec_passes = 0
	for i in range(0, len(A)):
		if A[i] == 1 and (not any_failed):
			first_consec_passes += 1
		else:
			any_failed = True
	if not any_failed:
		print('100')
	elif any_failed and first_consec_passes < M:
		print('0')
	else:
		print(K)


t = int(input())
for i in range(0, t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a1 = a[:m]
	if len(set(a)) == 1 and list(set(a))[0] == 1:
		print(100)
	elif len(set(a1)) == 1 and list(set(a1))[0] == 1:
		print(k)
	else:
		print(0)


n = int(input())
for i in range(n):
	s = list(map(int, input().split()))
	r = list(map(int, input().split()))
	x = r[:s[1]]
	if r.count(1) == s[0]:
		print(100)
	elif x.count(1) == s[1]:
		print(s[2])
	else:
		print(0)


for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	L = list(map(int, input().split()))
	L1 = L[:M]
	if len(set(L)) == 1 and list(set(L))[0] == 1:
		print(100)
	elif len(set(L1)) == 1 and list(set(L1))[0] == 1:
		print(K)
	else:
		print(0)


def arr():
	t = int(input())
	for i in range(t):
		f = 0
		(n, m, k) = list(map(int, input().split()))
		a = list(map(int, input().split()))
		for i in range(len(a) - 1):
			if sum(a) == n:
				f += 100
				break
			elif sum(a) >= m:
				if sum(a[:m]) >= m:
					f += k
					break
				else:
					f += 0
					break
			else:
				f += 0
				break
		if f > 0:
			print(f)
		else:
			print('0')
arr()


for i in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	c = 0
	o = 0
	f = 0
	for i in a:
		if i == 1:
			c += 1
		if i == 0 and f == 0:
			o = c
			f = 1
	if c == n:
		print('100')
	elif o >= m:
		print(k)
	else:
		print(0)


for i in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	c = A.count(1)
	z = 0
	if c == n:
		print(100)
	else:
		for i in range(m):
			if A[i] == 1:
				z += 1
		if z == m:
			print(k)
		else:
			print(0)