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):
N, K = map(int, input().split())
freq = [0] * (10**5 + 1)
for n in range(N):
    a, b = map(int, input().split())
    freq[a] += b
    
for i, f in enumerate(freq):
    K -= f
    if K <= 0:
        print(i)
        break

Solution (Python):
if __name__ == '__main__':
	N, K = map(int, input().split())

	n=[]
	num=0
	for j in range(100000):
		n.append(0)

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

	for j in range(100000):
		num+=n[j]
		if(num>=K):
			break

	print(j+1)

Solution (Python):
read = lambda: map(int, input().split())
n, k = read()
N = 10 ** 5 + 10
c = [0] * N
for i in range(n):
    a, b = read()
    c[a] += b
for i in range(N):
    k -= c[i]
    if k <= 0:
        ans = i
        break
print(ans)

Solution (Python):
import sys

N , K = map(int, input().split())
box = []

for i in range(N):
    box.append([int(i) for i in input().split()])
    
box.sort()
cnt = 0
for i in range(N):
    cnt += box[i][1]
    if cnt >= K:
        print(box[i][0])
        sys.exit()

Solution (Python):


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
ans_nth=int(hyo[1])

hai=[]
for idx in range(0,N,1):
    mozir=input()
    hyo=mozir.split(' ')
    entr=tuple([int(mono) for mono in hyo])
    hai.append(entr)


kirei_hai=sorted(hai,key=lambda po:po[0])


ans_ent_ichi=-1
tmp_nth=0


while tmp_nth < ans_nth:
    ans_ent_ichi+=1
    tmp_nth=tmp_nth+kirei_hai[ans_ent_ichi][1]

print(kirei_hai[ans_ent_ichi][0])

Solution (Python):
n, k = map(int,input().split(" "))
num_count = dict()
for i in range(n):
    a, b = map(int, input().split(" "))
    if a not in num_count:
        num_count[a] = 0

    num_count[a] += b

temp = 0
for key in sorted(num_count.keys()):
    temp += num_count[key]
    if temp >= k:
        print(key)
        break

Solution (Python):
N,K=map(int,input().split())
A=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    T=[a,b]
    A.append(T)
A.sort()
counter=0
for i in range(N):
     counter+=A[i][1]
     if counter>=K:
         counter=i
         break   
print(A[counter][0])

Solution (Python):
from operator import itemgetter, attrgetter
NK = list(map(int,input().split()))
AB = sorted([tuple(map(int, input().split())) for _ in range(NK[0])],key = itemgetter(0))
for i,j in AB:
    NK[1] = NK[1] - j
    if NK[1]<=0:
        print(i)
        break

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

from collections import defaultdict
d = defaultdict(int)

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

d = sorted(d.items())

cnt = 0
for a,b in d:
  cnt += b
  if cnt >= K:
    print(a)
    break

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

tmp.sort(key=lambda x:x[0])
for t in tmp:
    K -= t[1]
    if K<=0:
        print(t[0])
        break

Solution (Python):
N,K = list(map(int,input().split()))
data = []
def insert(num,N,K):
    x = 0
    for i in range(N):
        x += num[i][1]
        if x >= K:
            print(num[i][0])
            break
num = [list(map(int,input().split())) for i in range(N)]
num.sort(key=lambda x:x[0])
insert(num,N,K)

Solution (Python):
from collections import defaultdict
N, K = map(int, input().split())
seq = defaultdict(lambda: 0) 
for i in range(N):
    a, b = map(int, input().split())
    seq[a] += b

values = list(seq.keys())

values.sort()
ans = 0
for i in range(len(values)):
    K -= seq[values[i]]
    if(K<=0):
        print(values[i])
        break

Solution (Python):
N,K=map(int,raw_input().split())
c=[0]*N
for i in range(N):
	a,b=map(int,raw_input().split())
	c[i]=(a,b)
c.sort()
i,j=0,0
while i<=K-1:
	i+=c[j][1]
	if i>=K:break
	j+=1
print c[j][0]

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

ab=[]
for i in range(n):
    ab.append([int(i) for i in input().split()])

ab2 = sorted(ab)

cum=0
for i in range(n):
    cum += ab2[i][1]
    if cum >= k: break

print(ab2[i][0])

Solution (Python):
N, K = map(int, raw_input().split())
a = []
b = []
for i in range(N):
    temp0, temp1 = map(int, raw_input().split())
    a.append(temp0)
    b.append(temp1)

index = sorted(range(N), key=a.__getitem__)

for i in range(N):
    K -= b[index[i]]
    if K <= 0:
        print(a[index[i]])
        break

Solution (Python):
def int_input():
    line = input()
    return [int(x) for x in line.split()]

n, k = int_input()
nums = {}

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

s = 0
for i, x in sorted(nums.values()):
    s += x
    if k <= s:
        print(i)
        break

Solution (Python):

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

ab = [[0, 0]] * N
for i in range(N):
    _a, _b = map(int, raw_input().split())
    ab[i] = [_a, _b]
ab.sort(key=lambda x:x[0])

j = 0
index = 0
while j < K:
    j += ab[index][1]
    if j < K:
        index += 1

print ab[index][0]

Solution (Python):
import sys
N,K=map(int, input().split())
p=[]
for i in range (0,N):
  r=list(map(int, input().split() )) 
  p.append(r)
p.sort()
k=0
for i in range(0,N):
  k+=p[i][1]
  if k>=K:
    print(p[i][0])
    sys.exit()

Solution (Python):
class Data:
    def __init__(self):
        self.datanum = 0
        self.datalen = 0


n, k = list(map(int, input().split(' ')))

data_list = []
for i in range(n):
    a, b = map(int, input().split(' '))
    data = Data()
    data.datanum = a
    data.datalen = b
    data_list.append(data)
sorted_list = sorted(data_list, key=lambda u: u.datanum)
output = 0
for data in sorted_list:
    output = data.datanum
    k -= data.datalen
    if k <= 0:
        break
print(output)

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

Solution (Python):
from collections import defaultdict as dd
def main():
    N, K = map(int, input().split())

    d = dd(int)
    for n in range(N):
        a,b = map(int, input().split())
        d[a] += b

    count = 0
    A = sorted(d.keys())
    for k in A:
        
        count += d[k]
        if count >= K:
            print(k)
            break

if __name__ == "__main__":
    
    
    main()

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

ab = [list(map(int, input().split())) for x in range(n)]

ends = [0 for x in range(10**5 + 1)]
for a, b in ab:
    ends[a] += b

for i, e in enumerate(ends):
    k -= e
    if k <= 0:
        print(i)
        break

Solution (Python):


n,k = map(int, raw_input().split())

array = [0]*(10**5+1)
num = 0        
index = 0
for i in range(n):
    a,b = map(int, raw_input().split())
    array[a] += b
for i in range(10**5+1):
    num += array[i]
    if(num>=k):
        index = i
        break
    

print(index)

Solution (Python):
n, k = map(int, raw_input().split())
ary = []
for i in xrange(n):
    a, b = map(int, raw_input().split())
    ary.append([a, b]) 
ary.sort(key=lambda x:x[0])
for i in xrange(n):
    k -= ary[i][1]
    if k <= 0:
        result = ary[i][0]
        break
print result

Solution (Python):
n, k = [int(x) for x in input().split(' ')]
exist = []
storage = [0 for x in range(10 ** 5+1)]
for i in range(n):
    a, b = [int(x) for x in input().split(' ')]
    storage[a] += b
sum = 0
for i in range(1, 10**5+1):
    sum += storage[i]
    if sum >= k:
        print(i)
        break
    else:
        continue

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

array = [None for i in range(n)]

for i in range(n):
    array[i] = [int(i) for i in input().split()]





sa = sorted(array)



cnt = 0

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

Solution (Python):
N, K = map(int, input().split())
ps = []
for i in range(N):
    a, b = map(int, input().split())
    ps.append([a, b])
ps = sorted(ps)
k = 0
for i in range(N):
    k += ps[i][1]
    if k >= K:
        print(ps[i][0])
        break

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

ab_list=[]

count = 0
for i in range(N):
    a,b = map(int,raw_input().split())
    ab_list.append([a,b])
    
ab_list = sorted(ab_list,key=lambda ab:ab[0])

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

Solution (Python):


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

array = [tuple(map(int, input().split(' '))) for i in range(N)]
array = sorted(array, key=lambda x: x[0])

count = 0
i = 0
while True:
    count = count + array[i][1]
    if count >= K:
        break
    i = i + 1

print(array[i][0])

Solution (Python):
a = list(map(int,input().split(" ")))
b = list()

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

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

ans = c[0][0]
tmp = 0


for i in range(a[0]):
    tmp = tmp + c[i][1]
    if tmp >= a[1]:
        ans = c[i][0]
        break

print(ans)

Solution (Python):
n, k = map(int, raw_input().split(' '))
d = {}

for i in range(n):
	a, b = map(int, raw_input().split(' '))
	if d.has_key(a):
		d[a] += b
	else:
		d[a] = b

l = d.keys()
l.sort()

s = 0
for i in l:
	s += d[i]
	if s >= k:
		print i
		break

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

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

l.sort(key=lambda x: x[0])

count = 0
for j in l:
    count += j[1]
    if k <= count:
        print(j[0])
        break

Solution (Python):
n, k = map(int, raw_input().split())
ab = {}
for i in range(n):
    l = map(int, raw_input().split())
    if l[0] not in ab:
        ab[l[0]] = [l[1]]
    else:
        ab[l[0]].append(l[1])
key = sorted(ab.keys())
x = 0
for i in key:
    sum = 0
    for j in ab[i]:
        sum += j
    x += sum
    if k <= x:
        print i
        break

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

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 S(): return input()


def main():
    n,k = LI()
    r = []
    for _ in range(n):
        r.append(LI())

    r = sorted(r)
    c = 0
    for a,b in r:
        c += b
        if k <= c:
            return a

print(main())

Solution (Python):
N,K = [int(x) for x in input().split()]
arr=[]
for i in range(N):
    arr.append([int(x) for x in input().split()])
    
arr.sort(key=lambda tup: tup[0])

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

Solution (Python):
import sys
import math
import collections
sys.setrecursionlimit(10000)

mod = 10**9 + 7

n, k = map(int, input().split())
dic = collections.defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    dic[a] += b
ls = []
for key in dic.keys():
    ls.append(key)
ls.sort()
for i in range(len(ls)):
    val = dic[ls[i]]
    if val >= k:
        print(ls[i])
        exit(0)
    else:
        k -= val

Solution (Python):
import sys
from collections import defaultdict

def main():
    line = sys.stdin.readline()
    lst = line.split()
    n = int(lst[0])
    k = int(lst[1])

    cnt_dic = defaultdict(int)
    for line in sys.stdin:
        lst = line.split()
        a = int(lst[0])
        b = int(lst[1])

        cnt_dic[a] += b

    cnt = 0
    for key in sorted(cnt_dic.keys()):
        val = cnt_dic[key]
        cnt += val

        
        if cnt >= k:
            print("%d" % key)
            break

    return 0

if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
n,K = list(map(int, input().split()))
seq = []
d = {}
for _ in range(n):
    a,b = list(map(int, input().split()))
    if a in d.keys():
        d[a] += b
    else:
        d[a] = b
c = 0
for k in sorted(d.keys()):
    ans = k
    
    c += d[k]
    if c >= K:
        ans = k
        break
print(ans)

Solution (Python):
import numpy as np

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

al = []
bl = []

for i in range(N):
	a,b = map(int, input().split())
	al.append(a)
	bl.append(b)

al = np.array(al)
bl = np.array(bl)

s = al.argsort()

bl = bl[s]
al = al[s]

c = 0

for a,b in zip(al,bl):
	c += b
	if c >= K:
		print(a)
		break

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

for _ in range(N):
    a, b = list(map(int, input().split()))
    val_dict[a] = val_dict.get(a, 0) + b

val_keys = sorted(val_dict.keys())

K_rest = K
for key in val_keys:
    K_rest -= val_dict[key]
    if K_rest <= 0:
        print(key)
        break

Solution (Python):
def linput():
    return list(map(int,input().split(" ")))


N,K=linput()
ab=[]
for i in range(N):
    ab.append(linput())

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

k=0
for i,r in enumerate(ab):
    k+=r[1]
    if k>=K:
        print(ab[i][0])
        break

Solution (Python):
n,k = map(int, input().split())
t = []
for i in range(n):
	ti = tuple(map(int, input().split()))
	t.append(ti)

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

res = 0
x = 0
for i in range(n):
	res = t[i][0]
	inc = t[i][1]
	x += inc
	if x >= k:
		break

print(res)

Solution (Python):
import sys
import math
sys.setrecursionlimit(10000)

mod = 10**9 + 7

n, k = map(int, input().split())
dic = {}
for i in range(n):
    a, b = map(int, input().split())
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b
ls = []
for key in dic.keys():
    ls.append(key)
ls.sort()
for i in range(len(ls)):
    val = dic[ls[i]]
    if val >= k:
        print(ls[i])
        exit(0)
    else:
        k -= val

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

pos = 0
for a, b in sorted(D):
    if pos + b < K:
        pos += b
    else:
        print a
        exit()

Solution (Python):
N,K = map(int,input().split())
d = {}
for n in range(N):
	a,b = map(int,input().split())
	if a in d:
		d[a] += b
	else:
		d[a] = b 
d2 = list(d)
d2.sort()
cnt = 0
for i in d2:
	cnt += d[i]
	if cnt >= K:
		print(i)
		break

Solution (Python):
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, K = rdi()
a = []
b = []

for i in range(N):
        ai, bi = rdi()
        a.append(ai)
        b.append(bi)

c = {}
for i in range(N):
        ai = a[i]
        bi = b[i]
        if ai not in c:
                c[ai] = bi
        else:
                c[ai] += bi
r = K
for x in sorted(c.keys()):
        y = c[x]
        r -= y
        if r <= 0:
                print x
                break

Solution (Python):
n, k = map(int, input().split())
arr = []
for _ in range(n):
    a, b = map(int, input().split())
    arr.append((a, b))
arr = list(sorted(arr))
cnt = 0
i = 0
ans = arr[-1][0]
while cnt < k:
    ans = arr[i][0]
    cnt += arr[i][1]
    i += 1
print(ans)

Solution (Python):
n,k = map(int, raw_input().split())
ab = []
for i in range(n):
  a,b = map(int, raw_input().split())
  ab.append((a,b))

ab.sort()
k -= 1
for a,b in ab:
  if k >= b:
    k -= b
  else:
    print a
    exit()

Solution (Python):
import collections

if __name__ == '__main__':
    n, k = map(int, input().split())
    counter = collections.defaultdict(int)

    for _ in range(n):
        a, b = map(int, input().split())
        counter[a] += b

    x = 0
    for i in sorted(counter):
        if x <= k <= x + counter[i]:
            print(i)
            break
        x += counter[i]

Solution (Python):
N, K = map(int, input().split())
A = {}
for _ in range(N):
    a, b = map(int, input().split())
    if not a in A:
        A[a] = 0
    A[a] += b

c = 0
for a in sorted(A.keys()):
    c += A[a]
    if c >= K:
        print(a)
        break

Solution (Python):

import numpy as np
N, K = map(int, input().split())
a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

a_order = np.argsort(a_list)
kc = 0
for i in range(N):
    kc += b_list[a_order[i]]
    if kc >= K:
        print(a_list[a_order[i]])
        break

Solution (Python):


import sys
import os
import math

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

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

A.sort()

i = 0
cnt = 0
for a in A:
    v = a[0]
    num = a[1]
    cnt += num

    if cnt >= K:
        print(v)
        break

Solution (Python):
temp=input().split()
N=int(temp[0])
K=int(temp[1])
ab=[[int(j) for j in input().split()] for i in range(N)]

ab.sort()
while ab[0][1]<K:
	K-=ab[0][1]
	del ab[0]
	
print(ab[0][0])

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

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

for i in range(100000):
    K -= cnt[i]
    if K <= 0:
        print(i + 1)
        break

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

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

d.sort(key=lambda x: x[0])

c = 0
for p in d:
    c += p[1]
    if c >= K:
        print(p[0])
        break

Solution (Python):

n,m=map(int,input().split())
dic={}
for i in range(n):
    x,y=map(int,input().split())
    if x not in dic:
        dic[x]=y
    else:
        dic[x]+=y
for i in sorted(dic.items()):
    m-=i[1]
    if m<=0:
        print(i[0])
        break;

Solution (Python):
N,K = map(int, raw_input().split())
ab = sorted(map(int, raw_input().split()) for _ in range(N))
c = 0
for a,b in ab:
  if c+b >= K:
    print a
    break
  c += b

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

Solution (Python):
n, k = map(int, raw_input().split())
d = {}
for i in xrange(n):
    a, b = map(int, raw_input().split())
    d[a] = d.get(a, 0) + b
i = 1
ks = sorted(d)
for e in ks:
    if i <= k < i+d[e]:
        print e
        break
    i += d[e]

Solution (Python):
N, K = map(int, input().split())
d = {}
for n in range(N):
    a, b = map(int, input().split())
    d[a] = d.get(a, 0) + b

keys = list(d.keys())
keys.sort()

cnt = 0
for k in keys:
    cnt += d[k]
    if cnt >= K:
        print(k)
        exit()
print(keys[-1])

Solution (Python):



n,k=map(int,input().split())
d={}
l=[]
for i in range(n):
    u,v=map(int,input().split())
    if u in d:
        d[u]+=v
    else:
        d[u]=v
        l.append(u)
l.sort()
for i in l:
    k-=d[i]
    if k<=0:
        print(i)
        break

Solution (Python):
n,k=map(int,raw_input().split())
cnt=[0]*(10**5+1)
for i in xrange(n):
    a,b=map(int,raw_input().split())
    cnt[a]+=b
for i in xrange(10**5+1):
    if k-cnt[i]<=0:
        print i
        break
    k-=cnt[i]

Solution (Python):

N, K = map(int, raw_input().split())    
ab = [map(int, raw_input().split()) for i in xrange(N)]
ab.sort()
for a, b in ab:
    if K <= b:
        print a
        break
    else:
        K -= b

Solution (Python):
import sys

stdin = sys.stdin


def na(): return map(int, stdin.readline().split())


def ns(): return stdin.readline().strip()


stack = []
n,k = na()
for i in range(n):
    stack.append(list(na()))
stack.sort(key=lambda x: x[0])

sp = 0
for x in stack:
    sp += x[1]
    if sp >= k:
        print(x[0])
        break

Solution (Python):
A = [0 for _ in xrange(10**5+10)]
N, K = map(int, raw_input().split())
for i in xrange(N):
    a, b = map(int, raw_input().split())
    A[a] += b

k = 0
for i in xrange(10**5+10):
    k += A[i]
    if k >= K:
        print i
        break

Solution (Python):
import sys
from collections import Counter

def solve():
    N, K = map(int, input().split())
    cntr = Counter()

    for i in range(N):
        ai, bi = map(int, sys.stdin.readline().split())
        cntr[ai] += bi

    cntr = sorted(cntr.items())
    

    cnt = 0

    for a, b in cntr:
        cnt += b

        if cnt >= K:
            print(a)
            return


if __name__ == '__main__':
    solve()

Solution (Python):
n,k = map(int, input().split())
a = []
for i in range(n):
    x,y = map(int, input().split())
    a.append((x,y))
a.sort()
for x,y in a:
    if y >= k:
        print(x)
        exit()
    else:
        k -= y