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:
from operator import itemgetter
n, k = map(int, input().split())

arr = []
k_sum = 0
for i in range(n):
  a, b = map(int, input().split())
  d = {}
  d['num'] = a
  d['count'] = b
  arr.append(d)
  
arr = sorted(arr, key=itemgetter('num'))

for i in range(n):
  k_sum += arr[i]['count']
  if k <= k_sum:
    print(arr[i]['num'])
    exit(0)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

array = []
for n, t in dict_num.items():
    array.append([n, t])

array.sort()

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

Submission status: Accepted

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

cnt = 0
for key in sorted(nums.keys()):
  cnt += nums[key]
  if cnt >= K:
    print(key)
    exit()

Submission status: Accepted

Solution code:
def examC():
    N, K = LI()
    d = defaultdict(int)
    element = set()
    for _ in range(N):
        a, b = LI()
        d[a] += b
        element.add(a)
    element = list(element)
    element.sort()
    for i in element:
        K -= d[i]
        if K<=0:
            ans = i
            break
    print(ans)
#    print(element)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
from collections import Counter
N, K = map(int, input().split())
c = Counter()
for _ in range(N):
    a, b = map(int, input().split())
    c[a] += b
for item in sorted(c.items(), key=lambda x: x[0]):
    if item[1] >= K:
        print(item[0])
        break
    else:
        K -= item[1]

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
S = sorted([list(map(int, input().split())) for i in range(N)])
count=0
for i in S:
    count=count+i[1]
    if count>=K:
        print(i[0])
        break

Submission status: Accepted

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

Submission status: Accepted

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

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

from collections import defaultdict


N,K = two_int()


query = []
for i in range(N):
    query.append(two_int() )

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

ans=0
sums=0
for q in query:
    if sums < K <= sums+q[1]:
        ans=q[0]
        break
    
    sums += q[1]

print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(N, K, inputs):
    values = list(map(string_to_int, inputs))
    values.sort(key=lambda x: x[0])
    count = 0
    for v in values:
        count += v[1]
        if count >= K:
            return v[0]


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, K] = string_to_int(input())
    ret = solve(N, K, inputs(N))
    print(ret)

Submission status: Accepted

Solution code:
num = list(map(int, input().split(' ')))
insert = num[0]
minimum = num[1]
mylist = [0 for i in range(insert)]

for i in range(insert):
    mylist[i] = (list(map(int, input().split(' '))))
    
sort_list = sorted(mylist)
sum_num = 0
for i in range(insert):
    sum_num += sort_list[i][1]
    if sum_num >= minimum:
        print(sort_list[i][0])
        break

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
from collections import defaultdict as dd
dic = dd(lambda: 0)
for i in range(n):
  a, b = map(int, input().split())
  dic[a] += b

for key in sorted(dic.keys()):
  if k <= dic[key]:
    print(key)
    break
  else:
    k -= dic[key]

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

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB.sort(key=lambda x: x[0])

    c = 0
    for a, b in AB:
        if K <= c + b:
            ans = a
            break
        c += b
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N, K = map(int, input().split())
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        AB.append([a, b])
    AB.sort(key=lambda x: x[0])

    c = 0
    for a, b in AB:
        if c <= K <= c + b:
            ans = a
            break
        c += b
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import heapq
n, k = map(int,input().split())
hq = []
for i in range(n):
  heapq.heappush(hq, tuple(map(int, input().split())))
length = 0
while(length < k):
  a, b = heapq.heappop(hq)
  length += b
print(a)

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    S = []
    for i in range(N):
        a, b = (int(i) for i in input().split())
        S.append((b, a))
    S.sort(key=lambda s: s[1])
    SS = [(0, 0)]
    for i in range(N):
        SS.append((S[i][0] + SS[i][0], S[i][1]))
    for b, a in SS:
        if K <= b:
            print(a)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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 u in ab:
    a,b=u
    k-=b
    if k<=0:
        print(a)
        break

Submission status: Accepted

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

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(key=lambda x: x[0])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Big Array
N, K = map(int, input().split())
a = [0]*(N)
b = [0]*(N)
R = [0]*(10**5+1)
ans = 0
for i in range(N):
    a[i], b[i] = map(int, input().split())
for i in range(N):
    R[a[i]] = R[a[i]] + b[i]
j = 0
while K > 0:
    K = K - R[j]
    ans = ans + 1
    j = j + 1
print(ans-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
nums = []
for _ in range(N):
    a, b = map(int, input().split())
    nums.append([a, b])
cnt = 0
nums.sort()
for num in nums:
    cnt += num[1]
    if cnt >= K:
        print(num[0])
        break

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
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:
    print(a)
    exit()

Submission status: Accepted

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

    ls = []
    ans = 0

    for i in range(n):
        ab = list(map(int, input().split()))
        ls.append(ab)
    
    ls.sort()

    index = 0

    for i in range(n):
        if index < k:
            index += ls[i][1]
        if index >= k:
            ans = ls[i][0]
            break
    
    print(ans)
        

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
a = []
M = 0
for i in range(N):
  a.append(tuple(map(int,input().split())))
a.sort()
for i in range(N):
    K = K-a[i][1]
    if K <= 0:
        print(a[i][0])
        break

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
AB=sorted([list(map(int,input().split())) for i in range(n)])
dic={}
C=[0]
for i in range(n):
    C.append(C[-1]+AB[i][1])
for i in range(n):
    if C[i]<k<=C[i+1]:
        print(AB[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])

i = 0
count = 0
while count < K:
    if ab[i][1] >= K:
        ans = ab[i][0]
        break

    else:
        count += ab[i][1]
        ans = ab[i][0]
        i += 1

print(ans)

Submission status: Accepted

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

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

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import sys
sys.stdin.readline

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

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import sys
sys.stdin

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

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Submission status: Accepted

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

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

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Submission status: Accepted

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

remain = K
for i in range(1, 10**5+1):
    if arr[i] != 0:
        remain -= arr[i]
    if remain <= 0:
        print(i)
        exit()

Submission status: Accepted

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

th = 0
for i in range(1, 10**5+1):
    if arr[i] != 0:
        th += arr[i]
    if th >= K:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
list = [list(map(int,input().split())) for i in range(N)]
a = {}
for l in list:
  if l[0] not in a:
    a[l[0]] = l[1]
  else:
    a[l[0]] += l[1]
a = sorted(a.items(), key=lambda x:x[0])
c = 0
for b in a:
  c += b[1]
  ans = b[0]
  if c >= K: break
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################
 
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
 
remain = K
for i in range(10**5+1):
    if ans[i] == 0:
        continue
 
    remain -= ans[i]
    if remain <= 0:
        print(i)
        exit()

Submission status: Accepted

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

ab.sort()
t = 0
for a, b in ab:
    t += b
    if t >= 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(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:
#!/usr/bin/env python3
import sys
import itertools

def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    ab = list(zip(a,b))
    ab.sort(key=lambda x: x[0])
    sumb =0
    123334
    for i in range(N):
        sumb+=ab[i][1]
        if sumb>=K:
            print(ab[i][0])
            return 
        
    

    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:
from collections import defaultdict

N,K=map(int,input().split())
dd=defaultdict(int)
for i in range(N):
    a,b=map(int,input().split())
    dd[a]+=b
l=sorted(dd.keys())
i=0
for ai in l:
    i+=dd[ai]
    if i>=K:
        print(ai)
        break

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort()
    cnt = 0
    for a, b in ab:
        cnt += b
        if cnt >= k:
            print(a)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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 key in sorted(counter.keys()):
    k -= counter[key]
    if k <= 0:
        break
print(key)

Submission status: Accepted

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

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

all=0
for index,item in enumerate(l):
    all+=item
    if all>=K:
        print(index)
        exit()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    N, K = map(int, lines[0].split())
    bn = [0] * (int(1e5) + 1)
    for line in lines[1:]:
        ai, bi = map(int, line.split())
        bn[ai] += bi
    cnt = 0
    for ai, bi in enumerate(bn):
        cnt += bi
        if K <= cnt:
            print(ai)
            break
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin
from operator import itemgetter


def main():
    lines = stdin.readlines()
    N, K = map(int, lines[0].split())
    abn = [[int(abi) for abi in line.split()] for line in lines[1:]]
    abn.sort(key=itemgetter(0))
    cnt = 0
    for ai, bi in abn:
        cnt += bi
        if K <= cnt:
            print(ai)
            break
    return


main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    lines = stdin.readlines()
    N, K = map(int, lines[0].split())
    abn = [[int(abi) for abi in line.split()] for line in lines[1:]]
    abn.sort()
    cnt = 0
    for ai, bi in abn:
        cnt += bi
        if K <= cnt:
            print(ai)
            break
    return


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
C = {}
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a not in C:
        C[a] = 0
    C[a] += b
    A.append(a)
A = sorted(list(set(A)))
cnt = 0
for i in range(len(A)):
    cnt += C[A[i]]
    if cnt>=K:
        print(A[i])
        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.sort()
sm=0 
for i in range(n):
    if sm+l[i][1]<k:
        sm+=l[i][1]
    else: 
        print(l[i][0])
        exit()

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

for i in range(1,100001):
  if i in dic:
    k -= dic[i]
    if k <= 0:
      print(i)
      break

Submission status: Accepted

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

dic = {}
for _ in range(n):
    a,b = map(int, input().split())
    if a not in dic:
        dic[a] = 0
    dic[a] += b

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

Submission status: Accepted

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

dic = {}
for _ in range(n):
    a,b = map(int, input().split())
    if a not in dic:
        dic[a] = 0
    dic[a] += b

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

Submission status: Accepted

Solution code:
res = 0
flag = False
n,k = map(int,input().split())
ab = []
for i in range(n):
	aa,bb = map(int,input().split())
	ab.append([aa,bb])

ab.sort()

for j in range(0,n):
	res = res + ab[j][1]
	if res >= k:
		print(ab[j][0])
		flag = True
	if flag == True:
		break

Submission status: Accepted

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

n,k = map(int,input().split())
li = []

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

li.sort()

cnt = 0

for i in range(n):
    cnt += li[i][1]

    if cnt >= k:
        print(li[i][0])
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline
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
for i in range(10 ** 5 + 1):
  if d[i] >= K:
    print(i)
    exit(0)
  else:
    K -= d[i]

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
lists=[0]*n
for i in range(n):
    lists[i]=tuple(map(int,input().split()))
lists=sorted(lists,key=lambda x: x[0])

count=0
num=0
for j in range(n):
    if count<k:
        count=count+lists[j][1]
        num=lists[j][0]

    else:
        break
print(num)

Submission status: Accepted

Solution code:
n, k = 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 >= k:
        print(i)
        break

Submission status: Accepted

Solution code:
import numpy as np
from bisect import bisect_left, bisect_right
N, K = map(int, input().split())
count = 0
lis = np.array([0] * (10 ** 5))
for n in range(N):
    a, b = map(int, input().split())
    lis[a - 1] += b
for n in range(100000):
    K -= lis[n]
    if K <= 0:
        print(n + 1)
        break

Submission status: Accepted

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

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

for a,b in nums:
    k -=b
    if k <=0:
        print(a)
        exit()

Submission status: Accepted

Solution code:

N,K = map(int,input().split())
a_num = [0 for i in range(10**5+1)]
for i in range(N):
    a,b = map(int,input().split())
    a_num[a] += b #aの場所にbを加算することによってKが0または負の値になるときの答えの数がわかる

for i in range(len(a_num)):
    K -= a_num[i]
    if K <= 0: #もしKが0以下になったらiが答えになる
        print(i)
        exit()

Submission status: Accepted

Solution code:
# C - Big Array

import numpy as np
import bisect

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

ab = sorted(ab, key = lambda x : x[0])
a, b = zip(*ab)
b = np.array(b)
b = b.cumsum()

ans_idx = bisect.bisect_left(b, K)
print(a[ans_idx])

Submission status: Accepted

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

array = []

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

array.sort()
index = 0
for a_b in array:
  index += a_b[1]
  if index >= k:
    print(a_b[0])
    break

Submission status: Accepted

Solution code:
from collections import defaultdict

n,k=map(int,input().split())
d=defaultdict(int)
for i in range(n):
    a,b=map(int,input().split())
    d[a]+=b
l=sorted(d.keys())
cnt=0
for i in l:
    cnt+=d[i]
    if cnt>=k:
        print(i)
        exit()

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.keys():
        d[a]+=b
    else:
        d[a]=b
l=sorted(d.keys())
cnt=0
for i in l:
    cnt+=d[i]
    if cnt>=k:
        print(i)
        exit()

Submission status: Accepted

Solution code:
# ABC061 C - Big Array
from operator import itemgetter
N,K = map(int,input().split())
A = []
B = []
AB = [[] for _ in range(N)]

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

AB.sort(key=itemgetter(0, 1))

ans = 0
if len(AB) == 1:
    ans = AB[0][0]
    print(ans)
    exit()

for i in range(N):
    if i == 0:
        AB[0].append(AB[0][1])
        continue
    AB[i].append(AB[i-1][2]+AB[i][1])

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    import math
    import collections
    import itertools

    n, k = map(int, input().split())
    a_b = [tuple(map(int, input().split())) for _ in range(n)]
    a_b.sort()

    sum_add_value = 0
    for v in a_b:
        sum_add_value += v[1]
        if sum_add_value >= k:
            print(v[0])
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

def main():
  n, k = na()
  ab = [na() for _ in range(n)]
  ab.sort(key = lambda x: x[0])
  cnt = 0
  for a, b in ab:
    cnt += b
    if cnt >= k:
      print(a)
      return

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 = sorted(ab)

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

Submission status: Accepted

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

sort_dict_num = sorted(dict_num.items(), key=lambda x:x[0])
checked = 0
for key, v in sort_dict_num:
  if checked < k <= checked + v:
    print(key)
    exit()
  else:
    checked += v

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, K = map(int, input().split())
    ab = list()
    for i in range(N):
        ab.append(list(map(int, input().split())))
    
    ab = sorted(ab)

    res = K
    for i in range(N):
        res -= ab[i][1]
        if res <= 0:
            print(ab[i][0])
            exit()

Submission status: Accepted

Solution code:
# coding: utf-8
n,k = map(int,input().split())
a_num = [0 for _ in range(10**5+1)]
for i in range(n):
    a,b = map(int,input().split())
    a_num[a] += b

for i in range(len(a_num)):
    k -= a_num[i]
    if k <= 0:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import heapq
n,k = map(int,input().split())
a = []
for i in range(n):
  heapq.heappush(a,tuple(map(int,input().split())))
while k:
  cur = heapq.heappop(a)
  if k <= cur[1]:
    print(cur[0])
    k = 0
  else:
    k -= cur[1]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort()
    cnt = 0
    for a, b in ab:
        cnt += b
        if cnt >= k:
            print(a)
            exit()


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=[list(map(int, input().split())) for i in range(n)]
r=[0]*(10**5+1)
for i in range(n):
    r[l[i][0]]+=l[i][1]
#print(r[:10])
c=0
for i in range(1,10**5+1):
    c+=r[i]
    if k<=c:
        print(i)
        break

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()
k = 0
for x in X:
    k+=x[1]
    if K<=k:
        print(x[0])
        break

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
Data = []
for _ in range(N):
    Data.append(list(map(int,input().split())))
Data.sort(key=lambda x:x[0])
num = 0
for i in range(N):
    a,b = Data[i]
    num += b
    if num >= K:
        ans = a
        break
print(ans)

Submission status: Accepted

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

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

st_sorted = sorted(st.items(), key=lambda x:x[0])

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

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
ans = 0
for i in range(10 ** 5 + 1):
    ans += num[i]
    if ans >= k:
        print(i)
        exit()

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))
B_sum = 0
for i in range(N):
  B_sum += AB[i][1]
  if B_sum >= K:
    print(AB[i][0])
    exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

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
cnt = 0
for i in range(10 ** 5 + 1):
    cnt += ans[i]
    if K <= cnt:
        print(i)
        sys.exit()

Submission status: Accepted

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

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

li = sorted(li.items())
ans = 0
for i in range(len(li)):
    ans += li[i][1]
    if ans >= k:
        print(li[i][0])
        exit()

Submission status: Accepted

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

for i in range(1, 10**5+1):
    if K <= cnt[i]:
        print(i)
        exit()
    K -= cnt[i]

Submission status: Accepted

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