Skip to content

Instantly share code, notes, and snippets.

@czgdp1807
Last active November 16, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czgdp1807/1b879d27c98cf118d825e4db7ea56dab to your computer and use it in GitHub Desktop.
Save czgdp1807/1b879d27c98cf118d825e4db7ea56dab to your computer and use it in GitHub Desktop.
import sys
def read():
return list(map(int, sys.stdin.readline().strip().split()))
def is_good(array, start, end, K):
if any([array[i] == 0 for i in range(start, end + 1)]):
return True
neg_nums = 0
for i in range(start, end + 1):
if array[i] < 0:
neg_nums += 1
if neg_nums % 2 != 0:
return True
prod = 1
for i in range(start, end + 1):
if array[i] > 0:
if array[i] >= K/prod:
return False
else:
prod *= array[i]
num1, num2 = None, None
for i in range(start, end + 1):
if array[i] < 0:
if num1 is None:
num1 = array[i]
elif num2 is None:
num2 = array[i]
if num1 is not None and num2 is not None:
if num1*num2 >= K/prod:
return False
else:
prod *= num1*num2
num1, num2 = None, None
return True
N, K = read()
array = read()
good_tuple_count = 0
for i in range(N):
for j in range(i, N):
if is_good(array, i, j, K):
good_tuple_count += 1
print(good_tuple_count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment