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



Sample input:
3 4
1 1
2 2
3 3


Sample output:
3

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    count1 = 0
    count2 = 0
    d = []
    l = defaultdict(int)
    
    for i in range(N):
        a,b = map(int, input().split())
        l[a] += b


    for i, j in sorted(l.items()):
        count2 += j
        if count2 >= K:
            print(i)
            break
        

        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import deque,Counter

N,K = map(int,input().split())
cnt = Counter()
for _ in range(N):
    A,B = map(int,input().split())
    cnt[A] += B

sortedKeys = sorted(list(cnt.keys()))

tmp = K
for k in sortedKeys:
    tmp -= cnt[k]
    if tmp <= 0:
        print(k)
        exit()

Submission status: Accepted

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

for i in range(N):
    AB[i]=list(map(int,input().split()))
AB.sort()

ans=0
i=0
while K>0 and i<N:
    K-=AB[i][1]
    ans=AB[i][0]
    i+=1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
c = [0] * (10**5+1)
for _ in range(n):
  a,b = map(int,input().split())
  c[a] += b

A = np.array(c,dtype=np.int64)
A = A.cumsum()
answer = (A >= k).nonzero()[0].min()
print(answer)

Submission status: Accepted

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

d.sort(reverse=True)
while K > 0:
  a, b = d.pop()
  K -= b

print(a)

Submission status: Accepted

Solution code:
def main():
    N,K = map(int,input().split())

    A,AB = set(),{}
    for i in range(N):
        a,b = map(int,input().split())
        if a not in A:
            A.add(a)
            AB[a] = b
        else:
            AB[a] += b

    A = list(A)
    A.sort()

    for i in range(len(A)):
        K -= AB[A[i]]
        if K <= 0:
            ans = A[i]
            break

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
a_b = [list(map(int, input().split())) for i in range(N)]
a_b.sort()
index = 0

for i in range(N):
    index += a_b[i][1]
    if index >= K:
        print(a_b[i][0])
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
N, K = map(int, input().split())

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

total = 0
for k, v in sorted(cnt.items()):
    total += v
    if total >= K:
        print(k)
        exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 15:58:56 2020

@author: shinba
"""

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

data = {}

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

Data = sorted(data.items())

l = 0

for i,j in Data:
    l += j
    if l >= k:
        print(i)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
di = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a in di:
        di[a] += b
    else:
        di[a] = b
di = list(di.items())
di.sort()
s = 0
for a, b in di:
    if s+b>=k:
        print(a)
        break
    s += b

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = map(int, input().split())
    d = defaultdict(int)

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

    # print(d)

    for i in range(1, 10 ** 5 + 1):
        K -= min(K, d[i])
        if K <= 0:
            ans = i
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().split())
    d = defaultdict(int)
    for _ in range(N):
        a, b = map(int, readline().split())
        d[a] += b
    A = sorted(d.items(), key=lambda x:x[0])
    count = 0
    for key, value in A:
        count += value
        if count>=K:
            print(key)
            break
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
n = [0]*(int(1e5)+1)

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

for i in range(int(1e5)+1):
    K -= n[i]
    if K <= 0:
        print(i)
        break

Submission status: Accepted

Solution code:
def main():
    from itertools import accumulate

    n, k, *ab = map(int, open(0).read().split())
    c = list(zip(ab[::2], ab[1::2]))
    c.sort(key=lambda x: x[0])
    count = 0
    for i, j in c:
        count += j
        if k <= count:
            print(i)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter

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

counter = Counter()

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

for a in sorted(counter.keys()):
    b = counter[a]
    if K <= b:
        print(a)
        break
    K -= b

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    a, b = [0 for i in range(n)], [0 for i in range(n)]
    for i in range(n):
        a[i], b[i] = [int(x) for x in input().split()]
    ans = solve(n, k, a, b)
    print(ans)


def solve(n, k, a, b):
    ab = [[a[i], b[i]] for i in range(n)]
    ab.sort(key = lambda x:x[0])
    back = 0
    for i in range(n):
        back += ab[i][1]
        if back >= k:
            return ab[i][0]
    return 


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    AB[i]=list(map(int,input().split()))
AB.sort()

ans=0
i=0
while K>0 and i<N:
    K-=AB[i][1]
    ans=AB[i][0]
    i+=1

print(ans)

Submission status: Accepted

Solution code:
n, k, *AB = map(int, open(0).read().split())
*AB, = zip(AB[::2], AB[1::2])
AB.sort()

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

Submission status: Accepted

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

ab = sorted(ab)
cnt = 0
for a, b in ab:
    cnt += b
    if cnt >= k:
        print(a)
        exit()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
array = []
sum = 0
for i in range(N):
    a,b = map(int,input().split())
    array.append([a,b])
array.sort(key = lambda x:x[0])
for i in range(N):
    sum += array[i][1]
    if sum >= K:
        print(array[i][0])
        exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a_b = []

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
ab = [LIST() for _ in range(N)]

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

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
S={}
for i in range(N):
  a,b=map(int,input().split())
  if a in S:
    S[a]+=b
  else:
    S[a]=b
T=sorted(S.items())
count=0
for i in range(len(T)):
  count+=T[i][1]
  if count>=K:
    print(T[i][0])
    break

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
S={}
for i in range(N):
  a,b=map(int,input().split())
  if a in S:
    S[a]+=b
  else:
    S[a]=b
T=sorted(S.items())
count=0
for i in range(len(T)):
  count+=T[i][1]
  if count>=K:
    print(T[i][0])
    break

Submission status: Accepted

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

lst = [0 for i in range(10**5+1)]
for i in range(n):
    ai, bi = map(int, input().split())
    lst[ai] += bi

for i in range(1, 10**5+1):
    k -= lst[i]
    if k <= 0: break

print(i)

Submission status: Accepted

Solution code:
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
dic2 = sorted(dic.items()) 
count = 0
for i in range(len(dic2)):
  count += dic2[i][1]
  if count >= k:
    print(dic2[i][0])
    break

Submission status: Accepted

Solution code:
from operator import itemgetter
n,k = map(int,input().split())
lists = []
cnt = 0
a_b = sorted([list(map(int,input().split())) for i in range(n)],key = itemgetter(0))
for a,b in a_b:
    cnt += b
    if cnt >= k:
        print(a)
        exit()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
L=[]
for i in range(N):
	a,b=map(int,input().split())
	L.append([a,b])
L=sorted(L)
for i in range(N):
	if L[i][1]<K:
		K-=L[i][1]
	else:
		print(L[i][0])
		exit()

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
L = sorted([list(map(int,input().split())) for _ in range(N)])
for e in L:
    K -= e[1]
    if K <= 0:
        print(e[0])
        exit(0)

Submission status: Accepted

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

X.sort()
cnt = 0
for i in range(n):
    a, b = X[i]
    cnt += b
    if cnt >= k:
        print(a)
        exit()

Submission status: Accepted

Solution code:
import bisect
n,k=map(int,input().split())
s=[0 for _ in range((10**5)+1)]
maxa=0
for i in range(n):
    a,b=map(int,input().split())
    s[a]+=b
    maxa=max(maxa,a)
s=s[:maxa]
#print(s)
for i in range(1,len(s)):
    s[i]+=s[i-1]
#print(s)
print(bisect.bisect_left(s, k))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    l.sort(key=lambda x:x[0])
    kosu=0
    for i in range(n):
        kosu+=l[i][1]
        if kosu>=k:
            print(l[i][0])
            break
resolve()

Submission status: Accepted

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque
from collections import Counter
from collections import OrderedDict

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

for i in range(N):
    a, b = map(int, input().split())
    if a not in od:
        od[a] = b
    else:
        od[a] += b
od = OrderedDict(sorted(od.items(), key=lambda x: x[0]))

for i in od.items():
    K -= i[1]

    if K <= 0:
        print(i[0])
        exit()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a in d:
        d[a] += b
    else:
        d[a] = b
dd = [(k, v) for k, v in d.items()]
dd = sorted(dd, key=lambda x: x[0])
cur = 0
tmp = -1
for a, b in dd:
    if cur >= k:
        break
    cur += b
    tmp = a
print(tmp)

Submission status: Accepted

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

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

ab.sort()

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

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,k = myinput()
ab = mylistinput(n)

ab = mysort(ab,0,False)
# print(ab)

count = 0
for i in range(n):
    a = ab[i][0]
    b = ab[i][1]
    count += b
    if count >= k:
        print(a)
        exit()
print("E")

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

def main():
    n,k = readInts()
    sum_ = 0
    l = []
    for i in range(n):
        a,b = readInts()
        l.append([a,b])
    l = sorted(l,key = lambda x:x[0])
    for a,b in l:
        sum_ += b
        if sum_ >= k:
            print(a)
            exit()


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int,input().split())
    L=[list(map(int,input().split())) for i in range(n)]
    L=sorted(L, key=lambda x: x[0])
    
    
    cnt=0
    for i in range(n):
        temp=cnt
        cnt+=L[i][1]
        if cnt==k:
            print(L[i][0])
            break
        elif cnt>k and temp<k:
            print(L[i][0])
            break
        elif cnt>k and temp>=k:
            print(L[i-1][0])
            break

    
resolve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,k=MI()
lis=[0 for i in range(10**5)]
for i in range(n):
    a,b=MI()
    lis[a-1]+=b
#print(lis)
sm=0
for i in range(10**5):
    sm+=lis[i]
    #print(sm)
    if sm>=k:
        print(i+1)
        sys.exit()

Submission status: Accepted

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

d = {}
for i in range(n):
  a,b = tuple(map(int,input().split()))
  d.setdefault(a,0)
  d[a]+=b
  
l = sorted(d.items())

t = 0
for a,b in l:
  t+=b
  if t>=k:
    print(a)
    break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
num = 0
q = []
for i in range(n):
    a,b = map(int,input().split())
    q.append((a,b))
q.sort()
for i in range(n):
    a, b = q[i][0], q[i][1]
    num += b
    if num >= k:
        print(a)
        exit()

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cnt = 0
for a,b in ab:
  cnt += b
  if cnt >= k: break
print(a)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort(key=lambda t: t[0])
cnt = 0

for a, b in ab:
    cnt += b
    
    if cnt>=K:
        print(a)
        exit()

Submission status: Accepted

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

L=[]

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

L=sorted(L)

count=0
for l in L:
    a,b=l
    count+=b
    if count>=K:
        print(a)
        break

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, K = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort()
    cur = 0
    for a, b in AB:
        if cur+b < K:
            cur += b
            continue
        else:
            return print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(n)]
ab.sort()
for a,b in ab:
  k-=b
  if k<=0:print(a);exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
T = sorted((tuple(map(int, input().split())) for _ in range(N)), key=lambda t: t[0])
k = 0
for t in T:
    k += t[1]
    if k >= K:
        print(t[0])
        break

Submission status: Accepted

Solution code:
[n,k]=list(map(int,input().split()))
ablist=[]
for i in range(n):
    ablist.append(list(map(int,input().split())))
ablist=sorted(ablist,key=lambda x:x[0])
bwa=[0]
for i in range(n):
    bwa.append(bwa[-1]+ablist[i][1])
ind=1
while True:
    if bwa[ind-1]<k<=bwa[ind]:
        break
    ind+=1
print(ablist[ind-1][0])

Submission status: Accepted

Solution code:
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
inc=0
for i in range(10**5+1):
    inc+=l[i]
    if inc>=k:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys

n,k = map(int,input().split())
elements = [list(map(int,input().split())) for _ in range(n)]

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

count = 0

for elem in elements:
    count += elem[1]
    if count >= k:
        print(elem[0])
        sys.exit()

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, k = map(int, input().split())
ab = [readints() for _ in range(n)]
# print(ab)
abab = sorted(ab)
# print(abab)
tmp = 0
for i in range(n):
    tmp += abab[i][1]
    if tmp >= k:
        print(abab[i][0])
        break

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline  # NOQA


def main():
    N, K = map(int, input().split())
    cnt = [0] * (1 + 10**5)

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

    total = 0
    for i in range(1, 10**5 + 1):
        total += cnt[i]
        if total >= K:
            ans = i
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline  # NOQA


def main():
    N, K = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = tuple(map(int, input().split()))

    ab.sort(key=itemgetter(0))
    
    cnt = 0
    for a, b in ab:
        cnt += b
        if cnt >= K:
            ans = a
            break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
s=sorted([[int(i) for i in input().split()] for l in range(n)])
c=0
for x in s:
    c+=x[1]
    if c>=k:
        print(x[0])
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
ab = [tuple(map(int, readline().split())) for _ in range(n)]
ab.sort()
for a, b in ab:
    k -= b
    if k <= 0:
        print(a)
        break

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
ab.sort()
for a, b in ab:
    if b >= k:
        print(a)
        exit()
    k -= b

Submission status: Accepted

Solution code:
from itertools import chain
N,K = map(int,input().split())
num_bool = [0]*(10**5)
numarray_ind = list()

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

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(n)]
nums.sort(key=lambda x: x[0])
cnt = 0
for a, b in nums:
    cnt += b
    if cnt >= k:
        print(a)
        break

Submission status: Accepted

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

L=sorted(L)
count=0

for i in range(N):
    t=L[i]
    a,b=t
    count+=b
    if count>=K:
        print(a)
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
s = 0
for a, b in AB:
    s += b
    if s >= K:
        ans = a
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
ab = [inpl() for _ in range(n)]
ab.sort()
cnt = 0
for a,b in ab:
    cnt += b
    if cnt >= k:
        print(a)
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
total = 0
for a, b in ab:
    total += b
    if k <= total:
        print(a)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ab=[]
for i in range(n):
  aa,bb=map(int,input().split())
  ab.append([aa,bb])
ab.sort(key=lambda x: x[0])
a,b=[],[]
for aa,bb in ab:
  a.append(aa)
  b.append(bb)
from itertools import accumulate
c=list(accumulate(b))
idx=-1
for i in range(n):
  if i==0:
    if 0<=k<=c[i]:
      idx=i
      break
    continue
  if c[i-1]<k<=c[i]:
    idx=i
    break
print(a[idx])

Submission status: Accepted

Solution code:
def main():
    from heapq import heappush, heappop

    import sys
    input = sys.stdin.readline

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

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

    while h:
        a, b = heappop(h)
        K -= b
        if K <= 0:
            print(a)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
d = {}
for i in range(N):
    a,b = map(int,input().split())
    d[a]= d[a]+b if a in d else b
dd = sorted(d)    
_sum = 0
for i in dd:
    _sum += d[i]
    if _sum >= K:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ab_inputs = [[int(j) for j in input().split()]for i in range(n)]

dic = {}
for ab in ab_inputs:
    a,b = map(int,ab)
    dic[a]=dic.get(a,0)+b

for s in sorted(dic.items(),key=lambda x:x[0]):
    k-=s[1]
    if k<=0:
        ans=s[0]
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
n,k=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x:x[0])
c=0
i=0
while True:
    if c<k and c+l[i][1]>=k:
        print(l[i][0])
        exit()
    else:
        c+=l[i][1]
        i+=1

Submission status: Accepted

Solution code:
from collections import defaultdict


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

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

d = sorted(d.items())

for i, j in d:
    cnt += j
    if cnt >= k:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
from itertools import accumulate
from bisect import bisect_left

lis = []
lis = [tuple(map(int, input().split())) for i in range(N)]
lis.sort()
Bs = [y for x, y in lis]
cB = list(accumulate(Bs))

print(lis[bisect_left(cB, K)][0])

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ab.sort()
b = [0]
for i in ab:
    b.append(b[-1]+i[1])
i = 0
while b[i]<k:
    i += 1
print(ab[i-1][0])

Submission status: Accepted

Solution code:
import sys
import re
import math
import collections

# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    d=[]
    for _ in range(n):
        d.append(list(ns()))
    d.sort()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
m=[]
for i in range(n):
  m.append(list(map(int,input().split())))
m=sorted(m, key=lambda thing: thing[0])
total=0
for i in range(n):
  total+=m[i][1]
  if total>=k:
    ans=m[i][0]
    break
print(ans)

Submission status: Accepted

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

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

d_keys=sorted(d.keys())
cnt=0
for i in d_keys:
  cnt+=d[i]
  if cnt>=k:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import itertools
n,k=map(int,input().split())
bl=[0]*(10**5+1)
for i in range(n):
  a,b=map(int,input().split())
  bl[a]+=b
ans=list(itertools.accumulate(bl))
for i in range(len(ans)+1):
  if k<=ans[i]:
    print(i)
    break

Submission status: Accepted

Solution code:
from collections import deque
n,k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cnt = 0
ans = 0
for a,b in ab:
  ans = a
  cnt += b
  if cnt >= k:break
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
for i in range(N):
    cnt += A[i][1]
    if cnt>=K:
        print(A[i][0])
        break