import?sys
import?re
class?Node:
????def?__init__(self,data?=?None,?next?=?None):
????????self.data?=?data
????????self.next?=?next
class?Queue:
????def?__init__(self):
????????self.head?=?Node()
????????self.tail?=?self.head
????def?put(self,n):
????????self.tail.next?=?Node(n)
????????self.tail?=?self.tail.next
????def?get(self):
????????return?self.head.next.data
????def?delete(self):
????????g?=?self.head
????????g.next?=?g.next.next
????????if?g.next==None:
????????????self.tail?=?g
def?funcname():
????s?=?sys.stdin.readline()
????r?=?re.findall(r'd+',?s)
????bridgelength?=?int(r[0])
????bridgeload?=?int(r[1])
????br?=?Queue()
????num?=?1
????sw?=?0
????sl?=?0
????while?True:
????????s?=?sys.stdin.readline()
????????if?s=="":
????????????break
????????r?=?re.findall(r'd+',?s)
????????for?i?in?range(0,len(r),2):
????????????l?=?int(r[i])
????????????w?=?int(r[i+1])
????????????sw?+=?w
????????????sl?+=?l
????????????br.put([num,l,w])
????????????while?sl-br.get()[1]?>=?bridgelength:
????????????????t?=?br.get()
????????????????sl?-=?t[1]
????????????????sw?-=?t[2]
????????????????br.delete()
????????????if?sw>bridgeload:
????????????????print(br.get()[0])
????????????????return
????????????num?+=?1
????print(-1)
funcname()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…