Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Painting Wall by jullios1104
def checkio(req, op):
op=([tuple(x) for x in op])
def fan(pat):
pat=sorted(pat)
a=pat[0]
i=1
while i=a1 and b2<=a2:
pass
if b1<=a2 and b2>a2 or b1-a2==1:
a=(a1,b2)
if b1>a2:
yield a2-a1+1
a=b
i+=1
yield a[1]-a[0]+1
def ran() :
for i in range(1,len(op)+1):
yield (sum(fan(op[:i])) ,i) #количество закрашенного, количество операций
for x,y in ran() :
if req<=x:
return y
return -1
print(checkio(20,[[1,2],[20,30],[25,28],[5,10],[4,21],[1,6]]))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(5, [[1, 5], [11, 15], [2, 14], [21, 25]]) == 1, "1st"
assert checkio(6, [[1, 5], [11, 15], [2, 14], [21, 25]]) == 2, "2nd"
assert checkio(11, [[1, 5], [11, 15], [2, 14], [21, 25]]) == 3, "3rd"
assert checkio(16, [[1, 5], [11, 15], [2, 14], [21, 25]]) == 4, "4th"
assert checkio(21, [[1, 5], [11, 15], [2, 14], [21, 25]]) == -1, "not enough"
assert checkio(1000000011, [[1, 1000000000], [11, 1000000010]]) == -1, "large"
Sept. 12, 2023