Problem:
 Score : 300 points    Problem Statement There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i -th operation (1≤i≤N) , b_i copies of an integer a_i are inserted into the array.
Find the K -th smallest integer in the array after the N operations.
For example, the 4 -th smallest integer in the array \{1,2,2,3,3,3\} is 3 .      Constraints  1≤N≤10^5   1≤a_i,b_i≤10^5   1≤K≤b_1…+…b_n  All input values are integers.         Input Input is given from Standard Input in the following format:  N  K  a_1  b_1  :  a_N  b_N       Output Print the K -th smallest integer in the array after the N operations.        Sample Input 1 3 4
1 1
2 2
3 3      Sample Output 1 3  The resulting array is the same as the one in the problem statement.       Sample Input 2 10 500000
1 100000
1 100000
1 100000
1 100000
1 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000      Sample Output 2 1

Solution (Python):


import sys
input = sys.stdin.readline

N, K = [int(ele) for ele in input().split()]
ab = [0]*N
for i in range(N):
    ab[i] = [int(ele) for ele in input().split()]


def main():
    ab.sort()  
    ans = 0
    k = 0
    for ele in ab:
        k += ele[1]
        if k < K:
            continue
        elif K <= k:
            ans = ele[0]
            break

    print(ans)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
        if i != n // i:
            divisors.append(n//i)
    return divisors


class Node():

    def __init__(self):
        self.idx = None
        self.left = None
        self.right = None
        self.parent = None
        return

    def pre_order(self):
        global pre_order_str
        pre_order_str += str(self.idx) + " "
        if self.left:
            self.left.pre_order()

        if self.right:
            self.right.pre_order()

    def in_order(self):
        global in_order_str

        if self.left:
            self.left.in_order()

        in_order_str += str(self.idx) + " "

        if self.right:
            self.right.in_order()

    def post_order(self):
        global post_order_str
        if self.left:
            self.left.post_order()

        if self.right:
            self.right.post_order()

        post_order_str += str(self.idx) + " "


class HeapHelper():
    """HeapContrler.
    完全二分木を二分ヒープで表現した配列 A に対して、
    HeapHelper.parent(idx) とするとそのノードの親の添字を返す
    存在しない場合は Falseを返す

    Returns:
        [type] -- [description]
    """

    def __init__(self):
        return

    @staticmethod
    def parent(i):
        if i == 1:
            return False

        return int(i/2)

    @staticmethod
    def left(i):
        l_idx = 2*i
        if H < l_idx:
            return False

        return l_idx

    @staticmethod
    def right(i):
        r_idx = 2*i + 1
        if H < r_idx:
            return False

        return r_idx


if __name__ == "__main__":
    main()

Solution (Python):
N, K = map(int, input().split())

A = [0] * 10**5

for i in range(N):
    a, b = map(int, input().split())
    A[a-1] += b

c = 0

for i in range(10**5):
    c += A[i]
    if c >= K:
        break

print(i+1)

Solution (Python):
from collections import defaultdict
N,K = map(int,input().split())
d = defaultdict(int)
for i in range(N):
    a,b = map(int,input().split())
    d[a] += b
ls = [(k,d[k]) for k in d.keys()]
ls.sort(key = lambda x:x[0])
cnt = 0
for i in range(len(ls)):
    cnt += ls[i][1]
    if cnt >= K:
        print(ls[i][0])
        break

Solution (Python):
N,K = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in [0]*N])
for a,b in ab:
    K -= b
    if K <= 0:
        print(a)
        break

Solution (Python):
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort()

s = [0] * (N+1)

for i in range(N):
    s[i+1] = s[i] + ab[i][1]
    if s[i] < K <= s[i+1]:
        print(ab[i][0])
        break

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

mod = 10**9+7

N,K = map(int,input().split())


inserts = [[] for i in range(N)]
for i in range(N):
    inserts[i] = [int(i) for i in input().split()]


inserts.sort()
cnt = 0
for insert in inserts:
    cnt += insert[1]
    ans = insert[0]
    
    if cnt >= K:
        break

print(ans)

Solution (Python):
N, K = map(int, input().split())
dic = {}
for i in range(N):
  a, b = map(int, input().split()) 
  if dic.get(a) is None:
    dic[a] = b
  else:
    dic[a] += b

ans = -1  
now = 0
for k, v in sorted(dic.items()):
  now += v
  if now >= K:
    ans = k
    break
print(ans)

Solution (Python):
N, K = map(int, input().split())
lst = [0] * (10**5 + 1)
length = 0


for i in range(N):
    ai, bi = map(int, input().split())
    lst[ai] += bi

for ai, bi in enumerate(lst):
    length += bi
    if length >= K:
        ans = ai
        print(ans)
        break

Solution (Python):
N, K = map(int, input().split())
lst_ab = sorted([tuple(map(int, input().split())) for _ in range(N)])
length = 0


for i in range(N):
    ai, bi = lst_ab[i][0], lst_ab[i][1]
    length += bi
    if length >= K:
        ans = ai
        print(ans)
        break

Solution (Python):
N, K = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(N)])
for i in range(N):
    if K > ab[i][1]:
        K -= ab[i][1]
    else:
        print(ab[i][0])
        exit()

Solution (Python):
N, K = map(int, input().split())
D = [0] * 100005
for i in range(N):
    a, b = map(int, input().split())
    D[a] += b

t = 0
for i in range(100005):
    t += D[i]
    if t >= K:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())
AB = [map(int, input().split()) for _ in range(N)]

l = {}
for a, b in AB:
	if a not in l:
		l[a] = b
	else:
		l[a] += b

k = K
for m in sorted(l):
	k -= l[m]
	if k <= 0:
		print(m)
		break

Solution (Python):
from sys import stdin
input = stdin.readline

from itertools import accumulate
from bisect import bisect_left

N, K = map(int, input().split())

memo = [0] * 100010
for _ in range(N):
    a, b = map(int, input().split())
    memo[a] += b

print(bisect_left(list(accumulate(memo)), K))

Solution (Python):
from sys import stdin
input = stdin.readline

from itertools import accumulate
from bisect import bisect_left

N, K = [int(i) for i in input().split()]

memo = [0] * 100010
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    memo[a] += b

print(bisect_left(list(accumulate(memo)), K))

Solution (Python):
from itertools import accumulate
from bisect import bisect_left

N, K = [int(i) for i in input().split()]

memo = [0] * 100010
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    memo[a] += b

print(bisect_left(list(accumulate(memo)), K))

Solution (Python):
from itertools import accumulate
from bisect import bisect_left

N, K = [int(i) for i in input().split()]

memo = [0] * (10 ** 5 + 10)
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    memo[a] += b

print(bisect_left(list(accumulate(memo)), K))

Solution (Python):
N, K = [int(i) for i in input().split()]

memo = [0] * (10 ** 5 + 10)
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    memo[a] += b

for i, b in enumerate(memo):
    if K <= memo[i]:
        print(i)
        quit()
    K -= memo[i]

Solution (Python):
N, K = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for _ in range(N)]

L.sort()
k = 0
for a, b in L:
    if k + b >= K:
        print(a)
        quit()
    k += b

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)


n,k= (int(i) for i in input().split())       









a = []
for i in range(n):
    a.append([int(i) for i in input().split()])
p = -1
a.sort()
while k>0:
    p+=1
    k-=a[p][1]
print(a[p][0])

Solution (Python):
import heapq
N, K = map(int, input().split())

l = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(l, (a, b))

k = 0
while K > k:
    a, b = heapq.heappop(l)
    k += b

print(a)

Solution (Python):
n, k = map(int, input().split())
l = [0 for i in range(10 ** 5 + 5)]
for i in range(n):
    a,b=map(int, input().split())
    l[a]+=b

n = 0
for i,x in enumerate(l):
    n+=x
    if n>=k:
        print(i)
        break

Solution (Python):
N,K = map(int,input().split(" "))

o = [0]*(100001)
for i in range(N):
    a,b = map(int,input().split(" "))
    o[a] += b

for i in range(100001):
    a = min(K,o[i])
    if a == K:
        print(i)
        exit()
    K -= a

Solution (Python):
N, K = map(int, input().split())
nums = []
for _ in range(N):
    nums.append(list(map(int, input().split())))
nums.sort()

sumb = 0
for n in nums:
    sumb += n[1]
    if sumb >= K:
        print(n[0])
        break

Solution (Python):
from collections import Counter
from functools import reduce

import bisect
import copy
import fractions
import math
import pprint

pp = pprint.PrettyPrinter(width = 150)
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    
    x = root(x)
    y = root(y)
    if x == y:
        return
    
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  
        return x
    else:
        node[x] = root(node[x])  
        return node[x]
def dfs(v):
    
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  
            continue
        if visited[v2] == True:  
            continue
        dfs(v2)


n, k = MI()
nums = sorted([LI() for _ in range(n)])
cnt = 0
for num, kosuu in nums:
    if cnt + kosuu < k:
        cnt += kosuu
    else:
        print(num)
        exit()

Solution (Python):
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]

ab = sorted(ab)

s = 0
ans =ab[0][0]

for i, j in enumerate(ab):
  s += j[1]
  if s >= K:
    ans = ab[i][0]
    break
  else:
    ans = j[0]
  
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
array = [0]*(10**5+1)
for _ in range(N):
    a, b = map(int, input().split())
    array[a] += b
ans = 0
for i in range(10**5+1):
    K -= array[i]
    if K<= 0:
        ans = i
        break
print(ans)

Solution (Python):
from collections import defaultdict


def read_input():
    n, k = map(int, input().split())

    tups = []
    for i in range(n):
        tups.append(list(map(int, input().split())))

    return n, k, tups

def submit():
    n, k, tups = read_input()

    occurs = defaultdict(int)

    for tup in tups:
        occurs[tup[0]] += tup[1]

    nums = list(occurs.items())
    nums.sort(key=lambda x : x[0])

    count = 0
    for num in nums:
        if k <= count + num[1]:
            print(num[0])
            return
        count += num[1]



if __name__ == '__main__':
    submit()

Solution (Python):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
m = {}
ml = set()

for i in range(n):
    a, b = map(int, input().split())
    ml.add(a)
        
    if m.get(a):
        m[a] += b
    else:
        m[a] = b

mm = list(ml)
mm.sort()
for v in mm:
    if k > m[v]:
        k -= m[v]
    else:
        print(v)
        break

Solution (Python):
from collections import defaultdict

N, K = map(int, input().split())
c = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    c[a] += b

counter = 0
for a, b in sorted(c.items(), key=lambda x: x[0]):
    counter += b
    if counter >= K:
        break
print(a)

Solution (Python):
N, K = map(int, input().split())
d = [0] * 100005
for i in range(N):
    a, b = map(int, input().split())
    d[a] += b

num = 0
for i in range(100005):
    if d[i] != 0:
        if num + d[i] >= K:
            print(i)
            break
        else:
            num += d[i]

Solution (Python):
n, k = map(int, input().split())

items = dict()
for _ in range(n):
    ta, tb = map(int, input().split())
    if ta in items.keys():
        items[ta] += tb
    else:
        items[ta] = tb

items = sorted(items.items())

tb = 0
key = 0
for key, val in items:
    tb += val
    if tb >= k:
        break
print(key)

Solution (Python):
N,K=map(int,input().split())
A_B=[list(map(int,input().split())) for _ in range(N)]
ans=0
A_B.sort()
for i in range(N):
    ans+=A_B[i][1]
    if ans>=K:
        print(A_B[i][0])
        break

Solution (Python):
n,k=map(int, input().split())
num=[0]*100001
for i in range(n):
    a,b = map(int, input().split())
    num[a] +=b
cnt = 0
for i in range(1, 100001):
    cnt += num[i]
    if cnt >= k:
        print(i)
        exit()

Solution (Python):
N,K=[int(x) for x in input().split()]

a_list=[0] * (10**5)
for i in range(N):
    a,b=[int(x) for x in input().split()]
    a_list[a-1]+=b

k=0
for i in range(len(a_list)):
    k+=a_list[i]
    if k >=K:
        break
print(i+1)

Solution (Python):
n, k = map(int, input().split())
aa = []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append([a, b])
aa.sort()
c = 0
for a, b in aa:
    if c < k:
        c += b
        if c >= k:
            ans = a
            break
print(ans)

Solution (Python):
n, k = [int(n) for n in input().split()]

l = {}
for i in range(n):
    a, b = [int(n) for n in input().split()]

    if a in l:
        l[a] += b
    else:
        l[a] = b

l = sorted(l.items())
c_ = 0
for a, b in l:
    c = c_ + b
    if c_ < k <= c:
        print(a)
        break
    else:
        c_ = c

Solution (Python):
N,K = map(int,input().split())
ab = []
for i in range(N):
    a,b = map(int,input().split())
    ab.append([a,b])
ab.sort()
while K > 0:
    for _ab in ab:
        K -= _ab[1]
        if K <= 0:
            print(_ab[0])
            break

Solution (Python):
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x: x[0])
ab.insert(0, [0, 0])

for i in range(1, N+1):
    a, b = ab[i]
    ab[i] = [a, ab[i-1][1] + b]

for i in range(N):
    if ab[i][1] < K <= ab[i+1][1]:
        ans = ab[i+1][0]
        break

print(ans)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k = f()
    pii = [[0,0] for i in range(n)]
    
    for i in range(n):
        x, y = f()
        pii[i][0] = x
        pii[i][1] = y

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

    cnt = 0
    for i in range(n):
        if cnt + pii[i][1] >= k:
            print(pii[i][0])
            return
        
        cnt += pii[i][1]


solve()

Solution (Python):
n,k = map(int,input().split())
data = []
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if d.__contains__(a):
        d[a]+=b
    else:
        d[a] = b
data = list(d.items())
data.sort()

rank = 1

for x,cnt in data:
    if rank<=k and k<rank+cnt:
        print(x)
        break
    else:
        rank+=cnt

Solution (Python):


n,k=map(int,input().split())
a=[[] for i in range(n)]
for i in range(n):
    a[i]=list(map(int,input().split()))

a.sort(key=lambda x:x[0],reverse=True)
c=0
while c<k:
    x=a.pop()
    c+=x[1]
print(x[0])

Solution (Python):
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]

ab.sort()

i = -1

while k>0:
    i+=1
    k-=ab[i][1]

print(ab[i][0])

Solution (Python):
n,k=map(int,input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
c=0
for i in range(n):
  c+=li[i][1]
  if c>=k:
    print(li[i][0])
    
    break

Solution (Python):
n,k=map(int,input().split())
for s,t in sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0]):
    if k>t:
        k-=t
    else:
        print(s)
        exit()

Solution (Python):
N, K = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(N)]
l.sort(key=lambda x: x[0])
cnt = 0
for i in range(N):
    a = l[i][0]
    b = l[i][1]
    cnt += b
    if cnt >= K:
        print(a)
        break

Solution (Python):
n,k = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
now = 0
for i in a:
  now += i[1]
  if now >= k:
    print(i[0])
    break

Solution (Python):
n,k=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
A.sort()
i=-1
count=0
ans=0
while count<k:
  i+=1
  ans=A[i][0]
  count+=A[i][1]
print(ans)

Solution (Python):
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr, key=lambda x:x[0])
sum=0
for i in range(n):
  if sum<k<=sum+arr[i][1]:
    print(arr[i][0])
  sum=sum+arr[i][1]

Solution (Python):
n,k=map(int,input().split())
ab=[list(map(int, input().split())) for i in range(n)]
ab.sort()
count=0
ans=ab[0][0]
for i in range(n):
    if count+ab[i][1]<k:
        count+=ab[i][1]
    elif 0<=k-count<=ab[i][1]:
        ans=ab[i][0]
        break
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N,K=LI()
A=[]
B=[]
AB=[]
for i in range(N):
	a,b=LI()
	A.append(a)
	B.append(b)
	AB.append([a,b])
A=list(set(A))
A.sort()
counts={}
for a in A:
	counts[a]=0

for ab in AB:
	counts[ab[0]]+=ab[1]
if K<N/2:
	c=0
	for item in A:
		c+=counts.get(item)
		if c>=K:
			print(item)
			exit()
else:
	c=sum(B)
	for item in reversed(A):
		c-=counts.get(item)
		if c<K:
			print(item)
			exit()

Solution (Python):
n,k=map(int,input().split())
l=[0]*100001
for i in range(n):
    a,b=map(int,input().split())
    l[a]+=b
x=0
for i in range(100001):
    x+=l[i]
    if x>=k:break
print(i)

Solution (Python):
n,k = map(int, input().split())
array = {}

for i in range(n):
  a,b = map(int, input().split())
  if a in array: 
    array[a] += b
  else:
    array[a] = b
    

array_sorted = sorted(array.items())

ans = 0
cnt = 0

for elem in array_sorted:
  cnt += elem[1]
    
  if cnt >= k:
    
    print(elem[0])
    break

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n, k = nm()
lis = [nl() for _ in range(n)]
lis.sort()
count = 0
for i in range(n + 1):
    if count >= k:
        print(lis[i - 1][0])
        exit()
    count += lis[i][1]

Solution (Python):
n, k = [int(item) for item in input().split()]
ab = [[int(item) for item in input().split()] for _ in range(n)]

ab.sort()
count = 0
for i in range(n):
    count += ab[i][1]
    if count >= k:
        print(ab[i][0])
        exit()

Solution (Python):
I=lambda:list(map(int,input().split()))
N,K=I()
AB=sorted([I()for _ in[0]*N])
s=0
for a,b in AB:
  if s+b>=K:print(a);break
  s+=b

Solution (Python):
n, k = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x = sorted(x, key=lambda x: x[0])
idx = 0
ans = 0
for i in range(n):
    idx += x[i][1]
    if idx >= k:
        ans = x[i][0]
        break
print(ans)

Solution (Python):
N,K = map(int,input().split())

nums = []
for i in range(0,N):
    ab = list(map(int,input().split()))
    nums.append(ab)

nums = sorted(nums,key = lambda x: x[0])
tmp = 0
index = 0
for i in range(0,N):
    tmp += nums[i][1]
    if tmp >= K:
        index = i
        break

print(nums[i][0])

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N,K = (int(_) for _ in input().split())
    dict = {}
    ans = 0
    for i in range(N):
        s1,s2 = (int(_) for _ in input().split())
        if s1 not in dict:
            dict[s1] = s2
        else:
            dict[s1] += s2
    index = 0
    for k,v in sorted(dict.items()):
        index += v
        if(index >= K):
            ans = k
            break
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):








ab=[0]*(10**5+1)
lis=list(map(int,input().split()))
for i in range(lis[0]):
    t=list(map(int,input().split()))
    ab[t[0]]+=t[1]

ans=0
i=1
count=0
while count<lis[1]:
    count+=ab[i]
    ans=i
    i+=1

print(ans)

Solution (Python):



N, K = map(int, input().split())

l = [0] * (10 ** 5 + 1)
for i in range(N):
    a, b = map(int, input().split())
    l[a] += b
cnt = 0
for i in range(1, 10 ** 5 + 1):
    cnt += l[i]
    if cnt >= K:
        print(i)
        break

Solution (Python):
N, K = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))

AB = sorted(AB, key=lambda x: x[0])
for i in range(N):
    if i > 0:
        AB[i][1] += AB[i-1][1]
    if K <= AB[i][1]:
        print(AB[i][0])
        break

Solution (Python):
import sys
fastinput=sys.stdin.readline
N,K=map(int,fastinput().split())
data=[[int(j) for j in fastinput().split()] for k in range(N)]
ab=sorted(data,key=lambda x:x[0])
number=0
for a,b in ab:
    number+=b
    if number>=K:
        print(a)
        break

Solution (Python):
import sys
fastinput=sys.stdin.readline
N,K=map(int,fastinput().split())
data=[[int(j) for j in fastinput().split()] for k in range(N)]
ab=sorted(data,key=lambda x:x[0])
number=0
for a,b in ab:
    number+=b
    if number>=K:
        print(a)
        break

Solution (Python):
N,K = map(int,input().split())
dict = {}
for i in range(N):
  a,b = map(int,input().split())
  if(a in dict): dict[a] += b
  else: dict[a] = b

count = 0
ans = 0
for k, v in sorted(dict.items()):
   count += v
   if(count >= K): 
    ans = k
    break
print(ans)

Solution (Python):
n,k = map(int,input().split())
l = [0]*(10**5+1)
for _ in range(n):
    a,b = map(int,input().split())
    l[a] += b
for i in range(1,len(l)):
    l[i] += l[i-1]
    if k<=l[i]:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())

rules = []
for i in range(N):
    a, b = map(int, input().split())
    rules.append((a, b))

rules = sorted(rules, key=lambda x: x[0])
for rule in rules:
    K -= rule[1]
    if K <= 0:
        print(rule[0])
        break

Solution (Python):
n,k = map(int,input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()

cnt=0
for i in range(n):
  cnt+=li[i][1]
  if cnt>=k:
    print(li[i][0])
    break

Solution (Python):
N, K = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(N)]
arr.sort()
 
n = 0
for i in range(N):
	n += arr[i][1]
	if n >= K:
		print(arr[i][0])
		break

Solution (Python):
N, K = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(N)]
arr.sort()

n = 0
for i in range(N):
	n += arr[i][1]
	if n >= K:
		print(arr[i][0])
		break

Solution (Python):
N, K = list(map(int, input().split()))
num = [0] * (10 ** 5)
for i in range(N):
    a, b = list(map(int, input().split()))
    num[a - 1] += b

cnt = 0
for i in range(len(num)):
    cnt += num[i]
    if cnt >= K:
        print(i + 1)
        exit()

Solution (Python):
N, K = map(int, input().split())
AB = list(list(map(int, input().split())) for _ in range(N))

AB.sort()
if AB[0][1] >= K:
    ans = AB[0][0]
else:
    for i in range(1,N):
        AB[i][1] += AB[i-1][1]
        if AB[i][1] >= K:
            ans = AB[i][0]
            break
print(ans)

Solution (Python):
n, k = map(int, input().split())
count = 0
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab)
i = 0
while count < k:
  a, b = ab[i]
  count += b
  i += 1
  if count >= k:
    print(a)
    break

Solution (Python):
N, K = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
num = 0
for a, b in L:
    num += b
    if K <= num:
        print(a)
        exit()

Solution (Python):
import numpy as np
 
N, K = [int(i) for i in input().split()]
ab = np.array(
  [[int(i) for i in input().split()] for _ in range(N)])
 
idx_ab = np.argsort(ab[:, 0])
ab = ab[idx_ab, :]

k_sum = 0
 
for record in ab:
  a = record[0]
  b = record[1]
  
  k_sum += b
  if k_sum >= K:
    print(a)
    break

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append((a, b))

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

    cnt = 0
    for x in A:
        cnt += x[1]
        if cnt >= K:
            return x[0]


if __name__ == '__main__':
    print(main())

Solution (Python):
n,K=map(int,input().split());c={}
for i in range(n):
  a,b=map(int,input().split())
  if a in c:c[a]+=b
  else:c[a]=b
for k,v in sorted(c.items()):
  K-=v
  if K<=0:print(k);exit()

Solution (Python):
from sys import stdin

n, k = list(map(int, stdin.readline().split()))
ax = [0]*100001
c = 0
j = 0

for i in range(n):
    a, b = list(map(int, stdin.readline().split()))
    ax[a] += b

while c < k:
    c += ax[j]
    j += 1

print(j-1)

Solution (Python):
from operator import itemgetter
N, K = map(int, raw_input().split())
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))
a.sort(key=itemgetter(0))
thre = 0
for i in a:
    thre += i[1]
    if thre >= K:
        print(i[0])
        break

Solution (Python):
n,k = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
for i in range(n):
    if ab[i][1]>=k:
        print(ab[i][0])
        break
    else:
        k = k - ab[i][1]

Solution (Python):
N,M = map(int,input().split())
a = []
for _ in range(N):
    a.append(list(map(int,input().split())))
a.sort()
count = 0
for i in range(N):
    count += a[i][1]
    if count >= M:
        ans = a[i][0]
        break
print(ans)

Solution (Python):
N, K = map(int, input().split())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
a.sort()
sum = 0
for i, x in enumerate(a):
    sum += x[1]
    if sum >= K:
        print(a[i][0])
        break

Solution (Python):
import sys
N , K = map(int,input().split())
ablist = [list(map(int,input().split())) for _ in range(N)]
ablist.sort(key=lambda x: x[0])
for ab in ablist:
    K -= ab[1]
    if K <= 0:
        print(ab[0])
        sys.exit()

Solution (Python):
n, k = map(int, input().split())
a = sorted([list(map(int, input().split())) for _ in range(n)])
for i in range(n) :
  k -= a[i][1]
  if(k <= 0) :
    print(a[i][0])
    exit()

Solution (Python):
import sys
n,k=map(int,input().split())
number=[[int(i) for i in l.split()] for l in sys.stdin]
stack=[0]*(10**5+1)
for i in number:
  stack[i[0]]+=i[1]
acsum=[]
acSum=0
for i in stack:
  acSum+=i
  acsum.append(acSum)
def binary_search():
  ng=-1
  ok=10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if acsum[mid]>=k:
      ok=mid
    else:
      ng=mid
  return ok
print(binary_search())

Solution (Python):
arr = [0] * 100101
n,k = map(int,input().split())
for i in range(n):
    a,b = map(int,input().split())
    arr[a] += b
for i in range(100100):
    arr[i + 1] += arr[i]

for i,j in enumerate(arr):
    if j >= k:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
L.sort()
s = 0
for i in range(N):
    s += L[i][1]
    if s >= K:
        print(L[i][0])
        exit()

Solution (Python):


n,k = map(int,input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())

ab = [[0,0] for i in range(n)]

for i in range(n):
    ab[i] = [a[i],b[i]]

ab.sort()

cnt = 0

for i in range(n+1):
    if cnt >= k:
        print(ab[i-1][0])
        break
    cnt += ab[i][1]

Solution (Python):
from sys import stdin
n, k = map(int, input().split())
nums = [list(map(int, stdin.readline().split())) for _ in range(n)]
nums.sort(key=lambda x:x[0])
i = 0
while True:
    k -= nums[i][1]
    if k <= 0:
        print(nums[i][0])
        break
    i += 1

Solution (Python):
N, K =list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])

l=0
for a, b in AB:
  l+=b
  if l>=K:
    print(a)
    exit()

Solution (Python):
arr = [0] * 100100
n,k = map(int,input().split())
for i in range(n):
    a,b = map(int,input().split())
    arr[a] += b
for i in range(100010):
    arr[i + 1] += arr[i]
for i,j in enumerate(arr):
    if j >= k:
        print(i)
        exit()

Solution (Python):
N, K = map(int, input().split())
num = []

for k in range(N):
    a, b = map(int, input().split())
    num.append((a, b))

num = sorted(num)
cnt = 0
for i in num:
    cnt += i[1]
    if cnt >= K:
        print(i[0])
        break

Solution (Python):
from collections import defaultdict

N, K = map(int, input().split())

counts = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    counts[a] += b

for num in sorted(counts.keys()):
    K -= counts[num]
    if K <= 0:
        print(num)
        break

Solution (Python):


n,k, = map(int,input().split())
list = []
sum = 0
for i in range(n):
    a,b = map(int,input().split())
    list.append([a,b])

list.sort()
for i in range(n):
    sum = sum + list[i][1]
    if sum >= k:
        break
print(list[i][0])

Solution (Python):
def big_array(N: int, K: int, queries: list)->int:
    d = {}
    for a, b in queries:
        d.setdefault(a, 0)
        d[a] += b

    count = 0
    ans = 0
    for k, v in sorted(d.items()):
        count += v
        if K <= count:
            ans = k
            break
    return ans


if __name__ == "__main__":
    N = 0
    N, K = map(int, input().split())
    queries = [tuple(map(int, input().split())) for _ in range(N)]
    ans = big_array(N, K, queries)
    print(ans)

Solution (Python):
from operator import itemgetter
N,K = map(int,input().split())
c = [list(map(int,input().split())) for i in range(N)]
c.sort(key=itemgetter(0))
s = 0
for i in range(N):
    if s+c[i][1] < K:
        s += c[i][1]
    else:
        ans = c[i][0]
        break
print(ans)

Solution (Python):
N, K = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort()
tmp = K
for i in range(N):
    tmp -= a[i][1]
    if tmp <= 0:
        print(a[i][0])
        break