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())
s=[]
for i in range(n):
	x,y=map(int,input().split())
	s.append([x,y])
s.sort()
for i in range(n):
	k-=s[i][1]
	if k<=0:
		print(s[i][0])
		break

Submission status: Accepted

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

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

now = 0
ans = 0
for i, c in enumerate(count):
    now += c
    if now >= K:
        ans = i
        break

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    ab = []
    
    for _ in range(N):
        a,b = inputMap()
        ab.append((a,b))
        
    ab.sort()
    tmp = K
    
    for i, val in enumerate(ab):
        a,b = val
        tmp -= b
        if tmp <= 0:
            print(a)
            sys.exit()
    
if __name__ == "__main__":
	main()

Submission status: Accepted

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

ab.sort(key=lambda x:x[0])
i = 0
count = 0
while count < k:
    p = ab[i][0]
    count += ab[i][1]
    i += 1
print(p)

Submission status: Accepted

Solution code:
N, K = [int(v) for v in input().split()]
bins = [0] * (10 ** 5 + 1)
for _ in range(N):
    a, b = [int(v) for v in input().split()]
    bins[a] += b
cnt = 0
for i in range(1, len(bins)):
    cnt += bins[i]
    if cnt >= K:
        print(i)
        exit()

# for debug
print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ab.sort()
for i in range(N) :
    a, b = ab[i]
    if K > b :
        K -= b
    else :
        print(a)
        break

Submission status: Accepted

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

AB =sorted([tuple(map(int,input().split())) for i in range(N)])

B=0

for a,b in AB:
  #print(K,N,a,b,B)
  B+=b
  if B>=K :
    print(a)
    quit()
  #B+=b

Submission status: Accepted

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

lst = [list(map(int,input().split())) for _ in range(n)]
lst.sort(key = lambda x:x[0])
cnt = 0

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

print(ans)

Submission status: Accepted

Solution code:
M=lambda:map(int,input().split())
n,k=M();r=[]
for _ in[0]*n:
  r.append(list(M()))
for x,y in sorted(r):
  k-=y
  if k<1:
    print(x)
    exit()

Submission status: Accepted

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

Submission status: Accepted

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

l.sort()
count = 0
tmp = 0

for i in range(N):
    count += l[i][1]
    if count >= K:
        ans = l[i][0]
        break
    else:
        pass

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline


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

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

    l.sort()

    count = 0
    for index in range(n):
        count += l[index][1]

        if count >= k:
            break

    print(l[index][0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split()]
AB = [None]*N
for i in range(N):
    a, b = [int(x) for x in input().split()]
    AB[i] = (a, b) 
AB.sort()

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

Submission status: Accepted

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

for i in range(10**5+1):
  sum_a += num[i][1]
  ans = num[i][0]
  if sum_a >= k:
    print(ans)
    break

Submission status: Accepted

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

A = [[0]*2 for i in range(N)]



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

A.sort()

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

print(A[i][0])

Submission status: Accepted

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

li = []

for i in range(n):
    s,t = map(int,input().split())
    li.append([s,t])
    
li.sort()

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

Submission status: Accepted

Solution code:
#ABC061C
import sys
N, K = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
now = 0
ab.sort()
for a, b in ab:
    now += b
    if now >= K:
            print(a)
            sys.exit()

Submission status: Accepted

Solution code:
import sys
n, k = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]
tmp = {}
for l in li:
    if l[0] in tmp:
        tmp[l[0]] += l[1]
    else:
        tmp[l[0]] = l[1]
sorted_tmp = sorted(tmp.items())
for s in sorted_tmp:
    if k > s[1]:
        k = k -s[1]
    else:
        print(s[0])
        sys.exit()

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 = sorted(ab, key=lambda k:k[0])

b = 0

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
array=[]
for i in range(n):
    a,b=map(int,input().split())
    array.append((a,b))
array.sort()
i=0
import sys
while True:
    if array[i][1]<k:
        k-=array[i][1]
        i+=1
    else:
        print(array[i][0])
        sys.exit()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
opes = []
for _ in range(N):
  opes.append(tuple(map(int, input().split())))
opes.sort(key=lambda x:x[0])
sum_ope = 0
for ope in opes:
  sum_ope += ope[1]
  if sum_ope >= K:
    print(ope[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()
a_sum,i=0,0
while a_sum<k:
  a_sum+=ab[i][1]
  tmp=ab[i][0]
  i+=1
print(tmp)

Submission status: Accepted

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

while tmp<k:
  tmp+=ab[i][1]
  hoge=ab[i][0]
  i+=1

print(hoge)

Submission status: Accepted

Solution code:
from operator import itemgetter

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

AB.sort(key=itemgetter(0))

re = K
for a, b in AB:
    if re <= b:
        print(a)
        break
    re -= b

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
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
s=0
for i in range(10**5):
    if s+l[i]>=k:print(i+1);break
    else: s+=l[i]

Submission status: Accepted

Solution code:
import sys

n, k = (int(x) for x in sys.stdin.readline().split())
a_b_list = [[int(x) for x in sys.stdin.readline().split()] for y in range(n)]
a_b_list.sort(key=lambda x: x[0])
total_index = 0
for i in a_b_list:
    total_index += i[1]
for i in reversed(a_b_list):
    start = total_index
    end = total_index - i[1] + 1
    if start >= k >= end:
        print(i[0])
        sys.exit(0)
    total_index -= i[1]

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
ans = [0]*100000
for i in range(n):
    a, b = map(int,input().split())
    ans[a-1] += b
#print(ans)

counter = 0

while(k > 0):
    k -= ans[counter]
    counter += 1

print(counter)
    
#1

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
for i in range(a):
    d, e = map(int, input().split())
    c.append([d, e])
c.sort()
d = 0
for i in range(len(c)):
    d += c[i][1]
    if d >= b:
        print(c[i][0])
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
array = [list(map(int, input().split())) for i in range(N)]
array.sort(key=lambda x:x[0])
i,j = 0,0
while i < K:
  i += array[j][1]
  j += 1
print(array[j-1][0])

Submission status: Accepted

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

s=0
i=0
while s<k:
    s += m[i][1]
    i += 1
print(m[i-1][0])

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ab = [() for i in range(N)]
for i in range(N):
    ab[i] = tuple(map(int, input().split()))
    
ab.sort()
prev_ind = 0
cur_ind = 0
for (a, b) in ab:
    cur_ind = cur_ind + b
    if prev_ind < K and K <= cur_ind:
        print(a)
        break
    prev_ind = cur_ind

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
ab = {}
for i in range(n):
    a, b = map(int, input().split())
    try:
        ab[a] += b
    except:
        ab[a] = b
count = 0
ans = 0
for key in sorted(ab.keys()):
    count += ab[key]
    if count >= k:
        ans = key
        break
print(ans)

Submission status: Accepted

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

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

for tup in S:
    k-=tup[1]
    if k<=0:
        print(tup[0])
        break

Submission status: Accepted

Solution code:
from heapq import heappop,heappush

input=open(0).readline
n,k=map(int,input().split())
res={}
for i in range(n):
    a,b=map(int,input().split())
    res[a]=res.get(a,0)+b

que=[]
for key,val in res.items():
    heappush(que,(key,val))

while k:
    key,val=heappop(que)
    if val>=k:
        print(key)
        exit()
    k-=val

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
#ABC061C
import math

#n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

n=hoge[0]
k=hoge[1]

a=[]
b=[]
total=0
for i in range(0,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	a.append(hoge[0])
	b.append(hoge[1])
	total+=hoge[1]

c=[]
for i in range(0,n):
	c.append((a[i],b[i]))
c.sort()

#print(c)
#print(c[1][1])

thr=0
for i in range(0,n):
	thr+=c[i][1]
	if(thr>=k):
		print(c[i][0])
		break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = [0] * (10 ** 5)
for i in range(a):
    d, e = map(int, input().split())
    c[d-1] += e
f = 0
for i in range(10**5):
    f += c[i]
    if f >= b:
        print(i+1)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if a <= c <= b:
        print("Yes")
        return
    print("No")
    return

#B
def B():
    n, m = LI()
    e = defaultdict(int)
    for i in range(1, n + 1): e[i] = 0
    for i in range(m):
        a, b = LI()
        e[a] += 1
        e[b] += 1
    for i in e.values():
        print(i)
    return

#C
def C():
    n, k = LI()
    d = defaultdict(int)
    for i in range(1, 10**5+1): d[i] = 0
    for i in range(n):
        a, b = LI()
        d[a] += b
    for key, valus in d.items():
        k -= valus
        if k <= 0:
            print(key)
            return
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    C = [0] * 100001
    for _ in range(N):
        a, b = map(int, input().split())
        C[a] += b
    for i, c in enumerate(C):
        K -= c
        if 0 >= K:
            print(i)
            break


main()

Submission status: Accepted

Solution code:
import sys

def solve(N, K, ab):
    ab.sort(key=lambda x: x[0])

    s = 0
    for x in ab:
        s += x[1]
        if s >= K:
            print(x[0])
            return


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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import itertools

INF = 10**9+7

n,k = map(int,input().split())
ab = {}
for i in range(1,int(10e5+1)):
	ab[i] = 0
for i in range(n):
	a,b = map(int,input().split())
	ab[a] += b

def solve():
	global n,k,ab
	for ky,v in ab.items():
		if(v<k): k -= v
		else: return ky

def sgn(n):
	if(n>0): return 1
	if(n<0): return -1
	return 0

print(solve())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long k = Long.parseLong(sc.next());
		Map<Integer, Long> m = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			long b = Integer.parseInt(sc.next());
			if (m.get(a) != null) {
				b += m.get(a);
			}
			m.put(a, b);
		}
		long c = 0;
		for (Integer i:m.keySet()) {
			c += m.get(i);
			if (c >= k) {
				System.out.println(i);
				return;
			}
		}
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
A = []
for i in range(N):
    a, b = map(int, input().split(' '))
    A.append([a, b])
A.sort()
i = -1
count=0
while(True):
    i += 1
    count += A[i][1]
    if count >= M:
        print(A[i][0])
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC61 C

from operator import itemgetter

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

x = sorted(ab,key = itemgetter(0))
s = 0
for i,j in x:
    if s < k <= s+j:
        print(i)
        break
    s += j

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from operator import itemgetter
# input
n, k = map(int, input().split())
temp_array = []
addlist = temp_array.append
for i in range(n):
    addlist(list(map(int, input().split())))
temp_array.sort(key=itemgetter(0))
o = 0
for i in temp_array:
    o += i[1]
    if o >= k:
        print(i[0])
        exit()

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    num, k = map(int, input().split())
    data = defaultdict(int)
    for i in range(num):
        a, b = map(int, input().split())
        data[a] += b

    data = sorted(data.items(), key=lambda x: x[0])
    for aaa, count in data:
        k -= count
        if k <= 0:
            print(aaa)
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort()
b_sum = 0
for i in range(N):
    b_sum += ab[i][1]
    if K <= b_sum:
        print(ab[i][0])
        break

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
inp=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
for i,j in inp:
    if M>j:
        M-=j
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

def main(N,K,A):
    A = sorted(A, key=lambda x:x[0])
    tmp = A[0][0]
    for a, b in A:
        tmp = a
        if(0<K-b):
            K -= b
        else:
            print(tmp)
            break
    
if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [[int(i) for i in input().split()] for i in range(N)]
    main(N,K,A)

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])
tmp=0
for i in a:
    tmp+=i[1]
    if tmp>=k:
        print(i[0])
        exit()

Submission status: Accepted

Solution code:

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

now = 0
dic = {}
lis = []

for i in range(N):

    a,b = map(int,input().split())

    if a in dic:
        dic[a] += b
    else:
        dic[a] = b
        lis.append(a)

lis.sort()

for i in lis:

    now += dic[i]

    if now >= K:
        print (i)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
s=sorted([list(map(int,input().split())) for _ in range(n)])
ans=0
for a,b in s:
    ans+=b
    if k<=ans:
        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)]

count=[0]*(10**5+1)
for i in range(n):
    count[ab[i][0]]+=ab[i][1]

tmp=0
for i in range(len(count)):
    tmp+=count[i]
    if tmp>=k:
        print(i)
        quit()

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()
c=0
for i in range(n):
    c+=ab[i][1]
    if c>=k:
        print(ab[i][0])
        exit()

Submission status: Accepted

Solution code:
# 2019/07/05
# AtCoder Beginner Contest 061 - C

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

abl.sort()

cnt = 0
idx = 0
# Search k
while cnt < k:
    cnt += abl[idx][1]
    idx += 1

ans = abl[idx - 1][0]

# Output
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
d = {}
for _ in range(N):
    a,b = map(int,input().split())
    d[a] = d.get(a,0) + b
f = 0
for c in sorted(d.keys()):
    f += d[c]
    if f >= K:
        print(c)
        break

Submission status: Accepted

Solution code:
# 操作回数（N）および数を求めたい順位（K）を入力する
N, K = map(int, input().split())
# 挿入する整数（a）とその個数（b）の組を格納するリスト（list_ab）を定義する
list_ab = []
# 各操作において、、
for _ in range(N):
    # aおよびbを入力する
    a, b = map(int, input().split())
    # list_abにaとb個の組を追加する
    list_ab.append((a, b))
# list_abをaが昇順に並ぶようにソートする
list_ab.sort()
# bの合計を計算する変数（sum_b）を定義する
sum_b = 0
# 各a、bの組について、、
for a, b in list_ab:
    # sum_bにbを足す
    sum_b += b
    # sum_bがK以上になった場合、、
    if sum_b >= K:
        # aを出力する
        print(a)
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
cnt=dict()
for _ in range(n):
    a,b=map(int,input().split())
    cnt[a]=cnt.get(a,0)+b
cnt=sorted(cnt.items(),key=lambda x:x[0])

tmp=0
for key,val in cnt:
    tmp+=val
    if tmp >= k:
        print(key)
        exit()

Submission status: Accepted

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

d = {}
for i in range(n):
    if x[i] not in d:
        d[x[i]] = y[i]
    else:
        d[x[i]] += y[i]

d_sort = sorted(d)

sum = 0
for i in d_sort:
    if sum+d[i] >= k:
        print(i)
        break
    else:
        sum += d[i]

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
for a,b in sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0]):
    if k>b:
        k-=b
    else:
        print(a)
        break

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, K = map(int, input().split())
li = sorted([list(map(int, input().split())) for i in range(N)])
total = 0

for i in range(N):
    total += li[i][1]
    if total >= K:
        print(li[i][0])
        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,key=lambda x:x[0])
count=0
for i in ab:
    count+=i[1]
    if count>=K:
        print(i[0])
        exit()

Submission status: Accepted

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

def main():
    k = K
    a = {}
    for i in range(N):
        n, i = [int(s) for s in input().split()]
        if n not in a:
            a[n] = 0
        a[n] += i
    for n, i in sorted(a.items()):
        k -= i
        if k <= 0:
            ans = n
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
now = 0
d = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a in d.keys():
        d[a] += b
    else:
        d[a] = b

d = sorted(d.items())

for key, value in d:
    now += value
    if now >= K:
        print(key)
        exit()

Submission status: Accepted

Solution code:
import numpy as np
import copy


def main():
    N, K = map(int, input().split())
    x = np.empty((N, 2), dtype=np.int)
    for i in range(N):
        a, b = map(int, input().split())
        x[i, 0] = a
        x[i, 1] = b

    sort_idx = np.argsort(x[:, 0])
    x = x[sort_idx]
    cum_sum = np.cumsum(x[:, 1])
    idx = np.argwhere(cum_sum >= K)[0]

    print(int(x[:, 0][idx]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = []
for _ in range(N):
    A.append(list(map(int, input().split())))

A.sort(key=lambda x:x[0])
cur = 0
i = 0
while cur < K:
    cur += A[i][1]
    i += 1
print(A[i-1][0])

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
D,L={},[]
for _ in range(N):
    a,b=map(int,input().split())
    L.append(a)
    if a in D:D[a]=D[a]+b
    else:D[a]=b
l=list(set(L))
l.sort()
for i in l:
    K-=D[i]
    if K<=0:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n,k=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
cnt=0
for i in range(n):
    cnt+=ab[i][1]
    if k<=cnt:
        print(ab[i][0])
        sys.exit()

Submission status: Accepted

Solution code:
# C問題
N, K = map(int, input().split())
ab = []
for i in range(N):
    ab.append(list(map(int, input().split())))
ab.sort()
tmp_k = 0
tmp_i = 0
for i in range(N):
    tmp_k += ab[i][1]
    if tmp_k >= K:
        tmp_i = i
        break
print(ab[tmp_i][0])

Submission status: Accepted

Solution code:
n,k=[int(i) for i in input().split()]
ab=sorted([[int(j) for j in input().split()] for _ in range(n)],key=lambda x:x[0])
for a,b in ab:
    k-=b
    if k<=0:
        print(a)
        break

Submission status: Accepted

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


def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    ab = sorted([[a[i],b[i]] for i in range(N)], key=lambda x:x[0])
    nt = -1
    for ia,ib in ab:
        nt += ib
        if(nt >= K-1):
            print(ia)
            exit()
        
    print(ab[-1][0])


        


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, K, a, b)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split()]
op = [[int(i) for i in input().split()] for _ in range(N)]
op.sort(key=lambda x:x[0])

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

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(int)

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

sorted_d = sorted(d.items(), key=lambda x: x[0])

cnt=0
for k,v in sorted_d:
    cnt+=v
    if cnt>=K:
        print(k)
        exit()

Submission status: Accepted

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

ls = [[int(x) for x in input().split()] for _ in range(n)]

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

cnt = 0
now = 0

for i in range(n):
    cnt += ls[i][1]
    now = ls[i][0]
    if cnt >= k:
        print(now)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    p = []
    for i in range(N):
        p.append([a[i], b[i]])
    p.sort(key=lambda x:x[0])
    tmp = 0
    ret = 0
    for v, c in p:
        tmp += c
        if K <= tmp:
            ret = v
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, K, a, b)

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)]

stock = 0
from operator import itemgetter

AB.sort(key = itemgetter(0))

for a,b in AB:
    stock += b
    if stock >= k:
        print(a)
        break

Submission status: Accepted

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

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

p_list = []
t = zip(a, b)
ts = sorted(t)
a, b = zip(*ts)
ans = 0
count = 0
for ai, bi in zip(a, b):
    count += bi
    if count >= k:
        ans = ai
        break

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
d = [[0] * 2 for i in range(n)]
for i in range(n):
    d[i][0], d[i][1] = map(int, input().split())

d = sorted(d)
s = 0
ans = 0
for a, b in d:
    s += b
    ans = a
    if (s >= k):
        break


print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,k=(int(i) for i in input().split())
a=[[int(i) for i in input().split()] for i in range(n)]
#print(a)

a.sort()
i=0
ans=0
while ans < k:
    ans+=a[i][1]
    i+=1

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
c=[0]*100000
for i in range(n):
    a,b=map(int,input().split())
    c[a-1]+=b

i=0
count=0
while count<k:
    count+=c[i]
    i+=1

print(i)