Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()

query = []
for i in range(N):
    query.append(two_int() )

query = sorted(query, key=lambda x: x[0])

dicts = defaultdict(int)
count = 0
sums = 0

for [a,b] in query:
    temp = 0
    
    for k,v in dicts.items():
        if k>a:
            dicts[k] += b
        if temp <= k <= a:
            temp = k
            
    dicts[a] = b+dicts[temp]
    sums += b
    if sums > K:
        break

output = [ [k,v] for k,v in dicts.items()]

temp = sorted(output, key=lambda x: x[0])

ans=0
for i in range(len(temp)-1):
    if temp[i][1] < K <= temp[i+1][1]:
        ans=temp[i+1][0]
        break

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()


query = []
for i in range(N):
    query.append(two_int() )

query = sorted(query, key=lambda x: x[0])

ans=0
sums=0
for q in query:
    if sums < K <= sums+q[1]:
        ans=q[0]
        break
    
    sums += q[1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()

dicts = defaultdict(int)
count = 0
for i in range(N):
    a,b = two_int()
    temp = 0
    
    for k,v in dicts.items():
        if k>a:
            dicts[k] += b
        if temp <= k <= a:
            temp = k
            
    dicts[a] = b+dicts[temp]

output = [ [k,v] for k,v in dicts.items()]

temp = sorted(output, key=lambda x: x[0])

ans=0
for i in range(len(temp)-1):
    if temp[i][1] < K <= temp[i+1][1]:
        ans=temp[i+1][0]

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()


query = []
for i in range(N):
    query.append(two_int() )

query = sorted(query, key=lambda x: x[0])

ans=0
sums=0
for q in query:
    if sums < K <= sums+q[1]:
        ans=q[0]
        break
    
    sums += q[1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()

dicts = defaultdict(int)
count = 0
for i in range(N):
    a,b = two_int()
    temp = 0
    
    for k,v in dicts.items():
        if k>a:
            dicts[k] += b
        if temp <= k <= a:
            temp = k
            
    dicts[a] = b+dicts[temp]

output = [ [k,v] for k,v in dicts.items()]

temp = sorted(output, key=lambda x: x[0])

ans=0
for i in range(len(temp)-1):
    if temp[i][1] < K <= temp[i+1][1]:
        ans=temp[i+1][0]

print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()


query = []
for i in range(N):
    query.append(two_int() )

query = sorted(query, key=lambda x: x[0])

ans=0
sums=0
for q in query:
    if sums < K <= sums+q[1]:
        ans=q[0]
        break
    
    sums += q[1]

print(ans)