You are viewing a single comment's thread. Return to all comments →
def main(): import sys input = sys.stdin.read data = input().splitlines() n, k = map(int, data[0].split()) light = list(map(int, data[1].split())) # Convert light array to boolean light = [True if x == 1 else False for x in light] k -= 1 # Adjust k to be zero-indexed result = 0 last = -1 index = k while index < n: while index >= 0 and not light[index]: index -= 1 if index == -1 or index <= last: print(-1) return result += 1 last = index index += k * 2 + 1 if last + k + 1 < n: result += 1 l = False for i in range(n - 1, n - k - 2, -1): if light[i]: l = True break if not l: print(-1) return print(result) if __name__ == '__main__': main()
Seems like cookies are disabled on this browser, please enable them to open this website
Goodland Electricity
You are viewing a single comment's thread. Return to all comments →