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:
N,K = map(int,input().split())
l = []
for i in range(N):
  l.append( list(map(int,input().split())) )
l.sort()
  
a = [0]
b = [0]
for i in range(N):
  [x,y] = l[i]
  a.append(x)
  b.append(y)

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

Submission status: Accepted

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

Submission status: Accepted

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

nums.sort()

for i in range(N):
    n = min(K, nums[i][1])
    K -= n
    if K == 0:
        print(nums[i][0])
        break

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 x: x[0])


for a, b in AB:
    K -= b
    if K <= 0:
        print (a)
        exit()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    AB = [list(map(int, input().split())) for _ in range(n)]
    AB = sorted(AB, key=lambda x: x[0])

    for i in range(n):
        a, b = AB[i]
        if b < k:
            k -= b
        else:
            print(a)
            break


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
array = []
for i in range(n):
    a,b = map(int,input().split())
    array.append((a,b))
array.sort()
count = 0
for i in range(n):
    count += array[i][1]
    if count >= k:
        print(array[i][0])
        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(key=lambda x: x[0])

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

Submission status: Accepted

Solution code:
import heapq


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

q = []
for a, b in info:
    heapq.heappush(q, (a, b))

while q:
    a, b = heapq.heappop(q)
    if k <= b:
        print(a)
        exit()
    else:
        k -= b

Submission status: Accepted

Solution code:
def main():
    n, k = map(int, input().split())
    seq = {}
    for _ in range(n):
        a, b = map(int, input().split())
        if a in seq:
            seq[a] += b
        else:
            seq[a] = b
    seq = sorted(seq.items(), key=lambda x: x[0])
    answer = 0
    for n, c in seq:
        k -= min(c, k)
        if k <= 0:
            answer = n
            break
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]
from collections import Counter
ctr = Counter()
for a,b in AB:
    ctr[a] += b

for k,v in sorted(ctr.items()):
    if K <= v:
        print(k)
        exit()
    K -= v

Submission status: Accepted

Solution code:
import sys

N, K = map(int, sys.stdin.readline().rstrip().split())

opes = []
for _ in range(N):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    opes.append((a, b))
opes.sort()

count = 0
for (a, b) in opes:
    if count + b >= K:
        print(a)
        sys.exit()
    count += b

Submission status: Accepted

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

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

Submission status: Accepted

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

ablist=[]
for _ in range(N):
  a,b=map(int,input().split())
  ablist.append((a,b))
ablist.sort()
  
aslist=[]
s=0
for a,b in ablist:
  s+=b
  aslist.append((a,s))
#print(aslist)

for a,s in aslist:
  if s>=K:
    print(a)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k,*l=map(int,open(0).read().split())
for a,b in sorted(zip(l[::2],l[1::2])):
 k-=b
 if k<1:print(a);exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

array = []
n,k = map(int,input().split())
for i in range(n):
    a,b = map(int,input().split())
    array.append([a,b])
array.sort()
sumli = 0
for i in range(len(array)):
    sumli += array[i][1]
    if sumli>=k:
        break
print(array[i][0])

Submission status: Accepted

Solution code:
def nyu():
    N,K = map(int,input().split())
    A = [list(map(int,input().split())) for _ in range(N)]
    A.sort()
    return N,K,A

def kansu(N,K,A):
    
    sum = 0
    ans = -1


    for a in range(len(A)):
        sum += A[a][1]
#        print(sum,A[a][1])
        if (K <= sum):
            ans = A[a][0]
            break
    print(ans)




N,K,A = nyu()
kansu(N,K,A)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
d={}
l=[]
num=0
for i in range(n):
    a,b=map(int,input().split())
    try:
        d[a]+=b
    except:
        d[a]=b
        l.append(a)
l.sort()

for i in range(len(l)):
    num+=d[l[i]]
    if num>=k:
        print(l[i])
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

def main():
    N, K = map(int, input().split())
    a = [tuple(map(int, input().split())) for _ in range(N)]
    a.sort()
    i = 0
    while 1:
        K -= a[i][1]
        if K > 0:
            i += 1
        else:
            print(a[i][0])
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    n, k = map(int, stdin.readline().split())
    ab = [list(map(int, stdin.readline().split())) for _ in range(n)]
    ab.sort(key=lambda x: x[0])
    count = 0
    for a, b in ab:
        if count + b < k:
            count += b
        else:
            print(a)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
	bin = [0]*10**5
	n, k = map(int, input().split())
	for _ in range(n):
		a, b = map(int, input().split())
		bin[a-1] += b
	s = 0
	for i in range(len(bin)):
		s += bin[i]
		if s >= k:
			print(i+1)
			return
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

d = [0 for i in range(10**5)]

for i in range(n):
    d[l[i][0]-1] += l[i][1]

cnt = 0
for i in range(10**5):
    cnt += d[i]
    if cnt >= m:
        print(i+1)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n , k = map(int, input().split())
x=[]
j=0
c=0
for i in range(n):
    a , b = map(int, input().split())
    x.append([a,b])
x.sort(key = lambda x :x[0])
while True:
    c+=x[j][1]
    if c>=k:
        print(x[j][0])
        break
    j+=1

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort()
cnt=0
j=0
while cnt<k:
    cnt+=a[j][1]
    if cnt>=k:
        break
    else:
        j+=1
print(a[j][0])

Submission status: Accepted

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

ans_list=[0]*(10**5+1)
#print(len(ans_list))

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

#print(ans_list)
s=0
ans=0

for n,i in enumerate(ans_list):
  s+=i
  ans=n
  if s>=k:
    print(ans)
    break

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

N, K = map(int, input().split())
l = np.array([list(map(int, input().split())) for _ in range(N)])
a = l[np.argsort(l[:, 0])]

B = 0
for x in a:
  B += x[1]
  if B >= K:
    print(x[0])
    break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ll = []
for i in range(n):
    a, b = map(int, input().split())
    ll.append([a, b])
lls = sorted(ll)
cnt = 0
for i in range(n):
    cnt += lls[i][1]
    if cnt  >= k:
        print(lls[i][0])
        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())
dic = {}
cnt = [0 for i in range(100001)]
for i in range(n):
    s, t = map(int, input().split())
    cnt[s] += t
for i in range(1, 100002):
    if k <= cnt[i]:
        print(i)
        break
    k -= cnt[i]

Submission status: Accepted

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

p = [[0, 0] for i in range(n)]
for i in range(n):
  p[i] = list(map(int, input().split()))
  
p.sort()

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

Submission status: Accepted

Solution code:

def main2():
    import heapq
    n,k = map(int,input().split(" "))
    q = []
    for i in range(n):
        a,b = map(int,input().split(" "))
        heapq.heappush(q,(a,b))
    
    while k>0:
        a,b = heapq.heappop(q)
        k-=b
    
    print(a)
main2()

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[0])
k_ = 0
for a_, b_ in ab:
    k_ += b_
    if k_ >= k:
        print(a_)
        exit()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
N, K = map(int, readline().split())
X = [0] * (10**5+1)
for _ in range(N):
    a, b = map(int, readline().split())
    X[a] += b
for i, x in enumerate(X):
    K -= x
    if K <= 0:
        print(i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=sorted([list(map(int,input().split())) for i in range(n)])
now=0
for key,v in l:
    if v+now>=k:print(key);exit()
    now+=v

Submission status: Accepted

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

for j in list_ab:
    if b_sum < k:
        b_sum += j[1]
        cnt += 1
    else:
        break

print(list_ab[cnt-1][0])

Submission status: Accepted

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

for a,b in li:
  k -= b
  if k <= 0:
    print(a)
    break

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split()))
li=[]
for _ in range(n):
  a,b=list(map(int,input().split()))
  li.append([a,b])
li.sort()

for a,b in li:
  k -= b
  if k <= 0:
    print(a)
    break

Submission status: Accepted

Solution code:
n,k=list(map(int,input().split()))
li=[]
for _ in range(n):
  a,b=list(map(int,input().split()))
  li.append([a,b])
li.sort()

ans=0
for a,b in li:
  ans += b
  if k <= ans:
    print(a)
    break

Submission status: Accepted

Solution code:
N, K = 3, 4
ARR = [
    [1, 1],
    [2, 2],
    [3, 3],
]

# N,K = 10, 500000
# ARR = [
#     [1, 100000],
#     [1, 100000],
#     [1, 100000],
#     [1, 100000],
#     [1, 100000],
#     [100000, 100000],
#     [100000, 100000],
#     [100000, 100000],
#     [100000, 100000],
#     [100000, 100000]
# ]

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

def calculate(n, k, arr):
    dict = {}
    for ar in arr:
        if dict.get(int(ar[0])) == None:
            dict.__setitem__(int(ar[0]), int(ar[1]))
        else:
            dict.__setitem__(int(ar[0]), dict.__getitem__(ar[0]) + ar[1])

    kkk = 0
    for key in sorted(dict.keys()):
        kkk = kkk + dict.get(key)
        if kkk >= k:
            print(key)
            break


calculate(N, K, ARR)

Submission status: Accepted

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

A = []

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

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


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

print(A[i-1][0])

Submission status: Accepted

Solution code:
def resolve():
	n, k = map(int, input().split())
	B = [0]*10**5
	for _ in range(n):
		a, b = map(int, input().split())
		B[a-1] += b
	cnt = 0
	for i in range(len(B)):
		cnt += B[i]
		if cnt >= k:
			print(i+1)
			break
resolve()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
abn = [list(map(int, input().split())) for _ in range(N)]
abn.sort()
pool = 0
for ab in abn:
    pool += ab[1]
    if pool >= K:
        print(ab[0])
        break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = []
for i in range(n):
    a.append(list(map(int,input().split())))
a.sort(key = lambda x:x[0])
i = 0
while(1):
    k -= a[i][1]
    if k < 1:
        print(a[i][0])
        exit()
    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K =  list(map(int,input().split()))
listA = []
for i in range(N):
    listA.append(list(map(int,input().split())))
now = 0
listA.sort()
for i in range(N):
    if now <= K <= now+listA[i][1]:
        print(listA[i][0])
        exit()
    else:
        now += listA[i][1]

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


res=K
for i,l in enumerate(L):
    if l>0:
        res-=l
        if res<=0:
            print(i)
            break
#print(L)

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
ls_2dim = [0] * n
for i in range(n):
    a,b = map(int,input().split())
    ls_2dim[i] = [a,b]
ls_2dim.sort(key=lambda x: x[0])
count = 0
i = 0
while True:
    a,b = ls_2dim[i]
    count += b
    if count >= k:
        ans = a
        break
    i += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,k = map(int,input().split())
item_count = {}
for i in range(n):
    a,b = map(int,input().split())
    if a not in item_count:
        item_count[a] = 0
    item_count[a] += b
sorted_ls = sorted(item_count.items(), key = lambda x:x[0])
nums_ls = list(item_count.keys())
nums_ls.sort()
count_ls = [item[1] for item in sorted_ls]
csum_count = list(np.cumsum(count_ls))

def isOK(index, key, l):
    if l[index] >= key:
        return True
    else:
        return False
def meguru_search(l, key):
    left = -1
    right = len(l)
    while (right - left) > 1:
        mid = left + (right - left) // 2
        # 直感的に記憶　
            # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
            # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
        if isOK(mid, key, l):
            right = mid
        else:
            left = mid
    # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
    return right

ind = meguru_search(csum_count, k)
ans = nums_ls[ind]
print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
data = [0 for _ in range(10**5+1)]
for _ in range(N):
    a, b = map(int, input().split())
    data[a] += b

counter = 0
for i in range(10**10):
    if counter >= K:
        print(i-1)
        break
    counter += data[i]

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    N, K = list(map(int, input().split()))
    AB = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0])
    length = 0
    idx = 0
    val = None
    while True:
        if length >= K:
            break
        length += AB[idx][1]
        val = AB[idx][0]
        idx += 1
    print(val)
    

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
li=[0]*100001

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

tmp=0
for i in range(100001):
    tmp += li[i]
    if tmp >= K:
        print(i)
        break

Submission status: Accepted

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

from operator import itemgetter
S.sort(key=itemgetter(0)) 

#timesは今何番目に大きいものを表しているか
times=0
#indexは今のインデックス
index=0

while True:
    hoge = times+S[index][1]
    if hoge < K:
        times += S[index][1]
    else:
        re =S[index][0]
        break
    index += 1

print(re)

Submission status: Accepted

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

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

# print(lst)
lst.sort(key=lambda x:x[0])
# print(lst)

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

Submission status: Accepted

Solution code:
def resolve():
	n, k = map(int, input().split())
	arr = [0]*(10**5+1)
	for i in range(n):
		a, b = map(int, input().split())
		arr[a] += b
	for i in range(len(arr)):
		if arr[i] >= k:
			print(i)
			break
		k -= arr[i]
resolve()

Submission status: Accepted

Solution code:
class Node():
	def __init__(self, v, w):
		self._v = v
		self._w = w
	def v(self):
		return self._v
	def w(self):
		return self._w
def resolve():
	n, k = map(int, input().split())
	arr = []
	for i in range(n):
		a, b = map(int, input().split())
		arr.append(Node(a, b))
	arr.sort(key=lambda x: x.v())
	for v in arr:
		if v.w() >= k:
			print(v.v())
			break
		k -= v.w()
resolve()

Submission status: Accepted

Solution code:
from operator import itemgetter
n, k = map(int, input().split())
ab = []
A = 0
B = 1
for i in range(n):
    ab.append(list(map(int, input().split())))

ab.sort(key=itemgetter(0))
cnt = 0
ans = 0

for i in range(n):
    cnt += ab[i][B]
    if k <= cnt:
        ans = ab[i][A]
        break

print(ans)

Submission status: Accepted

Solution code:

n,k=map(int,input().split())
cnt=[0]*100001

for i in range(n):
    ai,bi=map(int,input().split())
    cnt[ai]+=bi
    
for ans in range(1,len(cnt)):
    if cnt[ans]>=k:
        print(ans)
        break
    k-=cnt[ans]

Submission status: Accepted

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

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

total = 0
for i in range(n):
    if total + ab_sorted[i][1] >= k:
        print(ab_sorted[i][0])
        exit()
    else:
        total += ab_sorted[i][1]

Submission status: Accepted

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

def main():
    N, K = map(int, readline().rstrip().split())
    d = {}
    for _ in range(N):
        a, b = map(int, readline().rstrip().split())
        d.setdefault(a, 0)
        d[a] += b
    
    keys, vals = d.keys(), d.values()
    z = zip(keys, vals)
    z = sorted(z)
    keys, vals = zip(*z)
    s = 0
    for k, v in zip(keys, vals):
        if s + v < K:
            s += v
        else:
            ans = k
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

array = sorted(array.items(), key = lambda x: x[0])
for i in range(10 ** 5 + 1):
    sum += array[i][1]
    if sum >= K:
        print(array[i][0])
        exit()

Submission status: Accepted

Solution code:

from collections import defaultdict
N, K = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
  a, b = map(int, input().split())
  d[a] += b
d = sorted(d.items(), key=lambda x:x[0])
s = 0
for i in range(len(d)):
  s += d[i][1]
  if K <= s:
    print(d[i][0])
    exit()

Submission status: Accepted

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

for i in range(n):
    ans.append(list(map(int,input().split())))

ans.sort()

for l in ans:
    x += l[1]
    if x < k:
        continue
    else:
        print(l[0])
        exit()

Submission status: Accepted

Solution code:
from collections import defaultdict
N, K = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
  a, b = map(int, input().split())
  d[a] += b
d = sorted(d.items(), key=lambda x:x[0])
s = 0
for i in range(len(d)):
  s += d[i][1]
  if K <= s:
    print(d[i][0])
    exit()

Submission status: Accepted

Solution code:
from collections import defaultdict
N, K = map(int,input().split())
d = defaultdict(int)
for _ in range(N):
    a, b = map(int,input().split())
    d[a] += b
cnt = 0
for i in range(1,10**5+1):
    cnt += d[i]
    if cnt >= K:
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
num_list = [0]*10**5
for i in range(n):
    a,b = map(int,input().split())
    num_list[a-1] += b
cnt = 0
for i in range(len(num_list)):
    cnt += num_list[i]
    if cnt >= k:
        print(i+1)
        break

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
l = sorted(list(list(map(int,input().split())) for _ in range(n)))
for a,b in l:
  k -= b
  if k<=0:
    print(a)
    break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ab=[]
for _ in range(n):
    ab.append(list(map(int,input().split())))
ab.sort(key=lambda x:x[0])
i=0
j=0
ans=0
while j<k:
    j+=ab[i][1]
    ans=ab[i][0]
    i+=1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [0]*(10**5+10)

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

sum = 0
for i in range(len(l)):
    sum += l[i]
    if sum >= m:
        print(i)
        break

Submission status: Accepted

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

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())
d = [0]*(10**5+1)
for i in range(N):
    a, b = map(int, input().split())
    d[a] += b

k = K
for i in range(len(d)):
    k -= d[i]
    if k <= 0:
        print(i)
        break

Submission status: Accepted

Solution code:
from collections import defaultdict
n,k=map(int,input().split())
ab=[input() for i in range(n)]
d = defaultdict(list)
[d[int(i.split()[0])].append(int(i.split()[1])) for i in ab]
sd=sorted(d.items(), key=lambda x:x[0])
c=0
for i,l in sd:
  c+=sum(l)
  if c>=k:
    print(i)
    exit()

Submission status: Accepted

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

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


li.sort()
for i in range(n):
    a,b = li[i]
    
    if k > b:
        k -= b
    else:
        print(a)
        exit()

Submission status: Accepted

Solution code:
def slove(ab_list, k):
    num_list = []
    count = 0
    for a, b in sorted(ab_list, key=lambda x: x[0]):
        count += b
        if count >= k:
            break

    return a

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    ab_list = [[int(i)for i in input().split()] for i in range(n)]
    print(slove(ab_list, k))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

cnt = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a not in cnt:
        cnt[a] = b
    else:
        cnt[a] += b

cnt = [[k, v] for k, v in cnt.items()]
cnt.sort()

s = 0
ans = 0
for k, v in cnt:
    s += v
    if s < K:
        continue
    else:
        ans = k
        break

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
list_score = [ list(map(int,input().split(" "))) for i in range(n)]
list_score.sort(key=lambda x:x[0])
cnt = 0
ans = -1
for i in range(n):
    cnt += list_score[i][1]
    if cnt >= k:
        ans = list_score[i][0]
        break

print(ans)

Submission status: Accepted

Solution code:
# =map(int,input().split())
n,m=map(int,input().split())
a =[list(map(int,input().split())) for i in range(n)]
a.sort()
import sys
# ans=dict(a)
# print(a)
cnt=0
for i in range(n):
    z=cnt+a[i][1]
    if z>=m:
        print(a[i][0])
        sys.exit()
    else:
        cnt=z

# print(a)
# for i in range(n):
#     for k in range(a[i][1]):
#         ans.append(a[i][0])
# print(ans)
# ans=[int(i) for i in ans]
# print(ans)
# print(ans[m-1])

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=[0]*1000000
for i in range(N):
  a,b=map(int,input().split())
  A[a-1]+=b
s=0
for i in range(100000):
  if A[i]==0: continue
  if s+A[i]<K:
    s+=A[i]
  else:
    print(i+1)
    exit()

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = []
b = []
for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)
cnt = {}
for i in range(n):
    cnt[a[i]] = 0
for i in range(n):
    cnt[a[i]] += b[i]
res = 0
for i in range(10**6):
    if i not in cnt:continue
    if res +cnt[i] >=k:
        ans = i
        break
    res += cnt[i]
print(ans)

Submission status: Accepted

Solution code:
"""
解説を読んでから、バケットソートで書き直した。
単純にリストのリストをソートすると、O(NlogN)かかる。
Nの最大値N_max個のバケットを用意してからバケットソートすると、O(N_max+A_max)になる。
A_max<=N_maxだから、要するにO(N_max)になる。
"""
N_max = 10**5+1

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

bucket_list = [0 for i in range(N_max)]
for i in range(N):
    a, b = map(int, input().split())
    bucket_list[a] += b
 
counter = 0
answer = None
for i in range(1, N_max):
    counter += bucket_list[i]
    if counter >= K:
        answer = i
        break
 
print(answer)

Submission status: Accepted

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

counter = 0
answer = None
for a_b_list in a_b_list_list:
    counter += a_b_list[1]
    if counter >= K:
        answer = a_b_list[0]
        break

print(answer)

Submission status: Accepted

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

nums = {}

for i in range(N):
  num, count = list(map(int, input().split()))
  if num in nums:
    nums[num] += count
  else:
    nums[num] = count

nums = sorted(nums.items(), key=lambda x:x[0])
count = 0
for num in nums:
  count += num[1]
  if K <= count:
    print(num[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())
    s[a] = s.get(a,0)+b
s = sorted(s.items(), key=lambda x:x[0])
for i in range(len(s)):
    k -=s[i][1]
    if k<=0:
        print(s[i][0])
        break

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort()
cnt = 0
for i in arr:
    cnt += i[1]
    if cnt >= K:
        print(i[0])
        exit()
print(arr[N-1][0])

Submission status: Accepted

Solution code:
import sys

n, k, *ab = map(int, sys.stdin.read().split())

def main():
  cnt = 0
  for a, b in sorted(zip(*[iter(ab)] * 2)):
    cnt += b
    if cnt >= k:
      print(a)
      return

if __name__ == '__main__':
  main()

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

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

ans = key_l[-1]
i = 0
for key in key_l:
    i+=d[key]
    if i >= k:
        ans = key
        break
print(ans)