Problem p03033 (python)

Fixed submission:
import sys
input = sys.stdin.readline
 
n,q = map(int,input().split())
imos = []
for i in range(n):
    s,t,x = map(int,input().split())
    imos.append((s-x,x))
    imos.append((t-x,-x))
ans = set()
j = 0
for i in range(q):
    d = int(input())
    imos.append((d,1e100))
imos.sort()
m = 1e100
flag = False
for t,stop in imos:
    if stop == 1e100:
        if ans:
            if not flag:
                m = min(ans)
                flag = True
            print(m)
        else:
            print(-1)
    elif stop > 0:
        ans.add(stop)
        if stop < m:
            m = stop
            flag = True
    else:
        ans.remove(-stop)
        if m == -stop:flag = False

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e.sort(key=lambda x:x[0])
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()

for t,f,x in e:
    while t > q[0]:
        q.popleft()
        if s:
            print(min(s))
        else:
            print(-1)
        if not q:
            sys.exit()
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
        
while q:
    q.pop()
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.readline
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e = sorted(e, key=lambda x:x[0])
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()

for t,f,x in e:
    while t > q[0]:
        q.popleft()
        if s:
            print(min(s))
        else:
            print(-1)
        if not q:
            sys.exit()
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
        
while q:
    q.pop()
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.readline
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e = sorted(e, key=lambda x:x[0])
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()

for t,f,x in e:
    while t > q[0]:
        q.popleft()
        if s:
            print(min(s))
        else:
            print(-1)
        if not q:
            sys.exit()
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
        
while q:
    q.pop()
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
from operator import itemgetter
import heapq
import sys
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e = sorted(e, key=itemgetter(0))
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()

for t,f,x in e:
    while t > q[0]:
        q.popleft()
        if s:
            print(min(s))
        else:
            print(-1)
        if not q:
            sys.exit()
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
        
while q:
    q.pop()
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e.sort()
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()
#print(e)
for t,f,x in e:
    while t > q[0] and q:
        #print((t,f,x,q.popleft()))
        q.popleft()
        if len(s) == 0:
            print(-1)
        else:
            print(min(s))
    if not q:
        sys.exit()
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
while q:
    q.pop()
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e.sort()
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()
#print(e)
for t,f,x in e:
    while t > q[0] and any(q):
        #print((t,f,x,q.popleft()))
        q.popleft()
        if len(s) == 0:
            print(-1)
        else:
            print(min(s))
    if not q:
        sys.exit()
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
while q:
    q.pop()
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
    
n,p=map(int,input().split())

e=[]
for _ in range(n):
    s,t,x = map(int,input().split())
    e.append((s-x,1,x))
    e.append((t-x,-1,x))
e.sort()
q = deque()
for _ in range(p):
    q.append(int(input()))
s=set()
#print(e)
for t,f,x in e:
    while t > q[0]:
        #print((t,f,x,q.popleft()))
        q.popleft()
        if len(s) == 0:
            print(-1)
        else:
            print(min(s))
    if f == 1:
        s.add(x)
    else:
        s.remove(x)
while q:
    q.pop()
    print(-1)