Buggy python submission (verdict: Time Limit Exceeded):
inp = input().split(" ")
N = int(inp[0])
K = int(inp[1])

arr = {}
keys = []

def bin_insert(arr, n, lo, hi):
	if lo == hi:
		return arr[:lo] + [n] + arr[lo:]
	mid = (hi+lo) // 2
	if n > arr[mid]:
		return bin_insert(arr, n, mid+1, hi)
	else:
		return bin_insert(arr, n, lo, mid)
	

for i in range(N):
	inp = input().split(" ")
	a = int(inp[0])
	b = int(inp[1])
	try:
		arr[a] += b
	except KeyError:
		arr[a] = b
		keys = bin_insert(keys, a, 0, len(keys))

for i in keys:
	K -= arr[i]
	if K <= 0:
		print(i)
		break

Fixed submission:
nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])

arr = []

for i in range(0, n):
	ab = input().split(' ')
	arr.append((int(ab[0]), int(ab[1])))

arr = sorted(arr)

pos = 0
while True:
	if k > arr[pos][1]:
		k -= arr[pos][1]
	else:
		print(arr[pos][0])
		break
	pos += 1

Buggy python submission (verdict: Time Limit Exceeded):
inp = input().split(" ")
N = int(inp[0])
K = int(inp[1])

arr = {}
keys = []

def bin_insert(arr, n, lo, hi):
	if lo == hi:
		return arr[:lo] + [n] + arr[lo:]
	mid = (hi+lo) // 2
	if n > arr[mid]:
		return bin_insert(arr, n, mid+1, hi)
	else:
		return bin_insert(arr, n, lo, mid)
	

for i in range(N):
	inp = input().split(" ")
	a = int(inp[0])
	b = int(inp[1])
	if a in arr:
		arr[a] += b
	else:
		arr[a] = b
		keys = bin_insert(keys, a, 0, len(keys))

for i in keys:
	K -= arr[i]
	if K <= 0:
		print(i)
		break

Fixed submission:
nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])

arr = []

for i in range(0, n):
	ab = input().split(' ')
	arr.append((int(ab[0]), int(ab[1])))

arr = sorted(arr)

pos = 0
while True:
	if k > arr[pos][1]:
		k -= arr[pos][1]
	else:
		print(arr[pos][0])
		break
	pos += 1

Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <queue>
#include <cstring>
#include <iterator>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;

    map<int, int> freq;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        if(!freq.count(a))
            freq[a] = 0;
        freq[a] += b;
    }

    map<int, int>::iterator it;
    int k = 1;
    for (it = freq.begin(); k <= K && it != freq.end(); it++) {
        k += it->second;
    }
    it--;
    cout << it->first << endl;
}

Fixed submission:
nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])

arr = []

for i in range(0, n):
	ab = input().split(' ')
	arr.append((int(ab[0]), int(ab[1])))

arr = sorted(arr)

pos = 0
while True:
	if k > arr[pos][1]:
		k -= arr[pos][1]
	else:
		print(arr[pos][0])
		break
	pos += 1

Buggy python submission (verdict: Runtime Error):
inp = input().split(" ")
N = int(inp[0])
K = int(inp[1])

arr = []
indicies = [0]

for i in range(N):
	inp = input().split(" ")
	a = int(inp[0])
	b = int(inp[1])
	if len(arr) == 0 or a >= arr[-1]:
		arr += [a] * b
		indicies.append(len(arr))
	elif a <= arr[0]:
		arr = ([a] * b) + arr
	else:
		for i in indicies:
			if a > arr[i-1] and a < arr[i]:
				arr = arr[0:i] + ([a] * b) + arr[i:]
	print(arr)

print(arr[K])


Fixed submission:
nk = input().split(' ')
n = int(nk[0])
k = int(nk[1])

arr = []

for i in range(0, n):
	ab = input().split(' ')
	arr.append((int(ab[0]), int(ab[1])))

arr = sorted(arr)

pos = 0
while True:
	if k > arr[pos][1]:
		k -= arr[pos][1]
	else:
		print(arr[pos][0])
		break
	pos += 1