Problem:
 Score : 300 points    Problem Statement Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.  There are N stores that sell energy drinks. In the i -th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.  What is the minimum amount of money with which he can buy M cans of energy drinks?  It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.      Constraints  All values in input are integers.  1 \leq N, M \leq 10^5  1 \leq A_i \leq 10^9  1 \leq B_i \leq 10^5  B_1 + ... + B_N \geq M         Input Input is given from Standard Input in the following format:  N  M  A_1  B_1  A_2  B_2  \vdots  A_N  B_N       Output Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.        Sample Input 1 2 5
4 9
2 4      Sample Output 1 12  With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.       Sample Input 2 4 30
6 18
2 5
3 10
7 9      Sample Output 2 130       Sample Input 3 1 100000
1000000000 100000      Sample Output 3 100000000000000  The output may not fit into a 32 -bit integer type.

Solution (Python):
n,m = map(int,input().split())
price = []
honsu = []
c = []
for i in range(n):
  a,b = map(int,input().split())
  c.append([a,b])
c = sorted(c)
price,honsu=zip(*c)
money = 0
l = 0
while m > 0:
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  l += 1
print(money)

Solution (Python):
N,M = map(int,input().split(" "))
arr = []
for i in range(N):
    a,b = map(int,input().split(" "))
    arr.append([a,b])

arr = sorted(arr)
sum = 0
i = 0
while M > 0:
    a = arr[i]
    b = min(M,a[1])
    sum = sum + b * a[0]
    M = M - b
    i = i + 1

print(sum)

Solution (Python):
n,m=map(int,input().split())
import numpy as np
data = np.zeros([n,2],dtype=np.int)
for i in range(n):
    a,b=map(int,input().split())
    data[i] = [a,b]
    


data_sort = data[np.argsort(data[:, 0])]


honsu = 0
money = 0
idx = 0
while(honsu<m):
    if (m-honsu)>data_sort[idx,1]:
        money+=data_sort[idx,0]*data_sort[idx,1]
        honsu += data_sort[idx,1]
        idx+=1
    else:
        money+=data_sort[idx,0]*(m-honsu)
        honsu += data_sort[idx,1]
        idx+=1
    
    
        
print(money)

Solution (Python):
import sys
def main():
  N,M = map(int, input().split())
  AB = []
  for _ in range(N):
    AB.append(list(map(int,input().split()))) 
  AB.sort(key = lambda x: x[0])
  ans = 0
  sumB = 0
  for row in AB:
    if row[1] > (M - sumB):
      ans += row[0] * (M - sumB)
      print(ans)
      sys.exit()
    else:
      ans += row[0] * row[1]
      sumB += row[1]
  print(ans)
main()

Solution (Python):
N , M = map(int,input().split())
a = []
for i in range(N):
    ll = list(map(int,input().split()))
    a.append(ll)

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

cash = 0
for i in range(N):
    if M == 0:
        break
    elif M - a_sort[i][1] > 0:
        cash += a_sort[i][0] * a_sort[i][1]
        M -= a_sort[i][1]
    else:
        cash += M * a_sort[i][0]
        M = 0
print(cash)

Solution (Python):
N, M = map(int, input().split())
d = []
for i in range(N):
    a, b = map(int, input().split())
    d.append((a, b))
d = sorted(d)
num = 0
ans = 0
for i in range(N):
    a, b = d[i]
    if num + b < M:
        num += b
        ans += a * b
    else:
        ans += a * (M - num)
        break

print(ans)

Solution (Python):
N,M = list(map(int,input().split()))
A = [tuple(map(int,input().split())) for _ in range(N)]
sortA = sorted(A,key= lambda x: x[0])
ans = 0
for i in range(N):
    if M-sortA[i][1]>0:
        ans += sortA[i][0]*sortA[i][1]
        M = M-sortA[i][1]
    else:
        ans += M*sortA[i][0]
        break
print(ans)

Solution (Python):
n, m = map(int, input().split())
ls = [(0, 0) for _ in range(n)]


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

ls = list(sorted(ls))

i = 0
_m = 0
total = 0

while _m < m:
    a, b = ls[i]
    _m += b
    total += a * b
    i += 1

a, b = ls[i - 1]
print(total - (_m - m) * a)

Solution (Python):
import heapq

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

ans = 0
drinks = 0
while drinks < M:
    a, b = heapq.heappop(stores)
    if b <= M - drinks:
        ans += a*b
        drinks += b
    else:
        ans += a*(M - drinks)
        drinks += M - drinks
print(ans)

Solution (Python):
N,M = map(int, input().strip().split(' '))
AB = [list(map(int, input().strip().split(' '))) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])
now_price = 0
remain_count = M
for a,b in AB:
  bay = min(remain_count, b)
  now_price += a*bay
  remain_count -= bay
print(now_price)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    L = []
    [L.append(list(map(int,input().split()))) for i in range(N)]
    L.sort(key=lambda x:x[0])
    
    drink = 0
    sougaku = 0
    
    
    for i in range(N):
        nedan, kazu = L[i]
        for j in range(kazu):
            if drink == M:
                break
            else:
                drink = drink + 1
                sougaku = sougaku + nedan
    
    print(sougaku)
   
if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

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

cost = 0
count = 0
for a, b in AB:
	if b < M - count:
		cost += a * b
		count += b
	else:
		t = M - count
		cost += a * t
		count += t
		break
print(cost)

Solution (Python):
N,m = list(map(int,input().split()))
data = [[0,0] for i in range(N)]
for i in range(N):
	data[i] = list(map(int,input().split()))
data.sort()
cost = 0
for i in range(N):
	prices,nums = data[i]
	if m > nums:
		cost += prices * nums
		m -= nums
	else:
		cost += prices * m
		print(cost)
		break

Solution (Python):
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort()
res = 0
for a,b in AB:
    res += a*min(b,m)
    m -= b
    if m < 0:
        break 
print(res)

Solution (Python):
N, M = [int(x) for x in input().split()]
V = [tuple(map(int, input().split())) for i in range(N)]
V.sort()

money = 0
count = 0

for a, b in V:
  if count + b < M:
    count += b
    money += a * b
  else:
    money += (M - count) * a
    break
print(money)

Solution (Python):
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, m = read_line(int, int)

x = []
for i in range(n):
    ai, bi = read_line(int, int)
    x.append((ai, bi))

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

cost = 0
for a, b in x:
    buy = min(m, b)
    m -= b
    cost += a * buy
    if m <= 0:
        print(cost)
        break

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

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

count=0
sum=0
for tup in dic:
    if tup[1] > m-count:
        sum+=tup[0]*(m-count)
        break
    sum+=tup[0]*tup[1]
    count+=tup[1]

print(sum)

Solution (Python):
N,M = map(int,input().split())
x = [list(map(int,input().split())) for i in range(N)]
x.sort(key=lambda x:x[0])
ans,cnt = 0,0
for i in range(N):
    if cnt+x[i][1]<M:
        ans += x[i][0]*x[i][1]
        cnt += x[i][1]
    else:
        ans += (M-cnt)*x[i][0]
        break
print(ans)

Solution (Python):
N, M = map(int,input().split())
Store = [tuple(map(int,input().split())) for i in range(N)]
Store.sort()

buy = 0
ans = 0

for price, num in Store:
    if buy+num < M:
        buy += num
        ans += price * num
    else:
        ans += (M - buy) * price
        break
print(ans)

Solution (Python):
text = input()
lines = text.split("\n")

lines = list(map(lambda x: x.split(" "), lines))
n_and_m = lines[0]
n = n_and_m[0]
m = n_and_m[1]
a_and_b = []
for i in range(int(n)):
    a_and_b.append(input().split(" "))


tmp = []

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


remain = int(m)

price = 0
for i in range(len(a_and_b)):
    for j in range(int(a_and_b[i][1])):
        remain = remain - 1
        price = price + int(a_and_b[i][0])
        if (remain == 0):
            break
    else:
        continue
    break
print(price)

Solution (Python):
import sys
from operator import itemgetter
input = sys.stdin.readline

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0))

count = 0
index = 0
for i in range(N):
    count += AB[i][1]
    if(count >= M):
        count -= AB[i][1]
        index = i
        break

money = 0
for i in range(index):
    money += AB[i][0]*AB[i][1]
money += (M-count)*AB[index][0]
print(money)

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

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


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


i = 0 
c = 0 
p = 0 
while c < M:
    a, b = AB[i]
    if c + b > M:
        d = (M - c) 
        c += d
        p += a * d
    else:
        c += b 
        p += a * b
    i += 1

print(p)

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

shop = {}
b = [0] * N


for i in range(N):
    tmp = list(map(int,input().split()))
    shop[i] = tmp[0]
    b[i] = tmp[1]


shop = sorted(shop.items(), key=lambda x:x[1])


ans = 0
tmp = 0
for i in range(N):
    if(tmp + b[shop[i][0]] >= M):
       ans += shop[i][1] * (M - tmp)
       break
    else:
        ans += shop[i][1] * b[shop[i][0]]
        tmp += b[shop[i][0]]


print(ans)

Solution (Python):
N,M=map(int,input().split())
x=[list(map(int,input().split())) for i in range(N)]
x.sort()
tmp,ans=0,0
for i in range(N):
    if tmp+x[i][1]<M:
        tmp+=x[i][1]
        ans+=x[i][0]*x[i][1]
    else:
        ans+=(M-tmp)*x[i][0]
        break
print(ans)

Solution (Python):
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=0
count=0
for i in range(n):
  if arr[i][1]<k-count:
    ans+=arr[i][0]*arr[i][1]
    count+=arr[i][1]
  else:
    ans+=arr[i][0]*(k-count)
    print(ans)
    break

Solution (Python):
n,m=map(int,input().split())
x=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0])
ans=0
for s,t in x:

    if m>=t:
        m-=t
        ans+=s*t
    else:
        ans+=m*s
        break
print(ans)

Solution (Python):
N,M = map(int,input().split())
ab = []
for i in range(N):
  ab += [list(map(int,input().split()))]
ab.sort()
rest = M
cost = 0
while True:
  if rest - ab[0][1] <= 0:
    cost += rest * ab[0][0]
    break
  else:
    rest -= ab[0][1]
    cost += ab[0][0] * ab[0][1]
    del ab[0]
print(cost)

Solution (Python):
N, M = map(int, input().split())
C = []
for _ in range(N):
    a, b = map(int, input().split())
    C.append((a, b))
C.sort()
ans = 0
for a, b in C:
    ans += a * min(b, M)
    M -= min(b, M)
    if M == 0:
        break
print(ans)

Solution (Python):
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(N)]
l.sort()
ans = 0
for i in range(N):
    if M - l[i][1] > 0:
        ans += l[i][0]*l[i][1]
        M -= l[i][1]
    else:
        ans += l[i][0]*M
        break
print(ans)

Solution (Python):
N,M = map(int, input().split())
 
AB = []
 
for i in range(N) : 
    tmp_AB = [int(i) for i in input().split()]
    AB.append(tmp_AB)
    
P = sorted(AB)
 
sum = 0
cnt = 0 

for i in range(len(P)) : 
    for j in range(P[i][1]) : 
        if cnt < M: 
            sum += P[i][0]
            cnt += 1
        else :
            break
        
    if cnt >= M : 
        break
    
print(sum)

Solution (Python):
n,k=map(int,input().split())
li=[]
for i in range (0,n):
  li.append(list(map(int,input().split())))
li.sort()
bought=0
pay=0
t=0
while bought<k:
  pay=pay+(li[t][0])*(li[t][1])
  bought=bought+li[t][1]
  t=t+1
pay=pay-li[t-1][0]*li[t-1][1]
bought=bought-li[t-1][1]
bought_2=k-bought
pay_2=li[t-1][0]*bought_2
pay=pay+pay_2
print(pay)

Solution (Python):
N,M = map(int,input().split())
list = [list(map(int,input().split())) for j in range(N)]
list = sorted(list)
tm = M
ans = 0
for li in list:
    if li[1] < tm:
        ans += li[0]*li[1]
        tm -= li[1]
    else:
        ans += li[0]*tm
        print(ans)
        exit()

Solution (Python):
N, M = [int(c) for c in input().split()]

shops = []
for _ in range(N):
    ab = [int(c) for c in input().split()]
    shops.append(ab)

cost = 0
bought = 0
s_shops = sorted(shops)

for shop in s_shops:
    buying = 0
    while buying < shop[1]:
        if bought == M:
            break
        cost += shop[0]
        buying += 1
        bought += 1

    if bought == M:
        break

print(cost)

Solution (Python):
n,m = map(int,input().split())
store = []
can_num = m
cost = 0

for i in range(n):
    store.append(tuple(map(int,input().split())))

store.sort()

while can_num > 0:
    lowest_store = store.pop(0)
    buy_num = lowest_store[1] if lowest_store[1] < can_num else can_num
    cost += buy_num * lowest_store[0]
    can_num -= buy_num

print(cost)

Solution (Python):
N, M=[int(x) for x in input().split()]
shopl = [[int(x) for x in input().split()] for _ in range(N)]
sl =sorted(shopl,key=lambda x:(x[0])) 
cnt = 0
price =0
for i in range(N):
    amt = min(sl[i][1], M - cnt)
    price += sl[i][0] * amt
    cnt +=amt
    if cnt == M:
      break
print(price)

Solution (Python):
N,M=map(int,input().split())
AB=[[0,0] for _ in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=map(int,input().split())
AB.sort(key=lambda x:x[0])
ans=0
drink_num=0
for i in range(N):
    if (AB[i][1]+drink_num)>=M:
        ans+=(M-drink_num)*AB[i][0]
        drink_num=M
    else:
        ans+=AB[i][1]*AB[i][0]
        drink_num+=AB[i][1]
    if drink_num==M:
        break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N,M = map(int, input().rstrip().split())
AB = [list(map(int, input().rstrip().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
count = 0
price = 0
for i in range(N):
    count += AB[i][1]
    price += AB[i][0]*AB[i][1]
    if count >= M:
        break
mod = count - M
if mod != 0:
    price -= AB[i][0]*mod
print(price)

Solution (Python):
x = list(map(int,input().split()))
a = [list(map(int,input().split())) for l in range(x[0])]

a.sort()
buy = 0
money = 0
for i in a:
  if (buy + i[1]) <= x[1]:
    money += i[0] * i[1]
    buy += i[1]
  else:
    money += i[0] * (x[1] - buy)
    break
    
print(money)

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

values = []
for i in range(stores):
    values.append([int(j) for j in input().split()])

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

expence = 0

for i in range(len(values)):
    if values[i][1] < target:
        expence += values[i][0] * values[i][1]
        target -= values[i][1]
    elif values[i][1] == target:
        expence += values[i][0] * values[i][1]
        break
    elif values[i][1] > target:
        expence += values[i][0] * target
        break
print(expence)

Solution (Python):
n,m=map(int,input().split())
list_ab=[]
for i in range(0,n):
    a,b=map(int,input().split())
    list_ab.append((a,b))
list_ab=sorted(list_ab)
cost=0
for i in range(0,n):
    a=list_ab[i][0]
    b=list_ab[i][1]
    if m<=b:
        cost=cost+a*m
        break
    else:
        cost=cost+a*b
        m=m-b
print(cost)

Solution (Python):
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()
totl=0
x=0
for j,k in a:
  if x+k<m:
    totl+=j*k
    x+=k
  else:
    totl+=j*(m-x)
    break
print(totl)

Solution (Python):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
t=[[0]*2 for i in range(n)]
for i in range(n):
  t[i]=[t[i-1][0]+ab[i][0]*ab[i][1],t[i-1][1]+ab[i][1]]
  if t[i][1]>=m:
    t[i][0]-=ab[i][0]*(t[i][1]-m)
    print(t[i][0])
    break

Solution (Python):
N,M=map(int,input().split())
a = []
cost = 0

for i in range(N):
    a.append(list(map(int, input().split())))
    
a = sorted(a, key=lambda x: x[0])
    
for i in range(N):
    while a[i][1] > 0:
        a[i][1] -= 1
        cost += a[i][0]
        M -= 1
        if M == 0:
            break
    if M == 0:
        break

print(cost)

Solution (Python):
n,m=map(int,input().split())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
l.sort()
x,ans=0,0
for i,j in l:
    if x+j<m:
        ans+=i*j
        x+=j
    else:
        ans+=i*(m-x)
        break
print(ans)

Solution (Python):
N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB.sort(key=lambda x:x[0])

kane = 0
hon = 0
for i in range(N):
    if hon + AB[i][1] < M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        continue
    elif hon + AB[i][1] == M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        print(kane)
        break
    else:
        kane += (M - hon) * AB[i][0]
        print(kane)
        break

Solution (Python):
N, M= map(int, input().split())
A = []
for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
count = 0
cost = 0
i = 0
while count < M:
    cost += A[i][0] * min(A[i][1],M-count)
    count += min(A[i][1],M-count)
    i += 1    
print(cost)

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

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

ans = 0
for i in range(N):
    a = sortedAB[i][0]
    b = sortedAB[i][1]
    if M == 0:
        print(ans)
        exit()
    if b <= M:
        ans += a*b
        M -= b
    else:
        ans += a*M
        M = 0

print(ans)

Solution (Python):
n, m = [int(i) for i in input().split()]
dic = {}
for i in range(n):
  a, b = [int(i) for i in input().split()]
  if not a in dic:
    dic[a] = b
  else:
    dic[a] += b
ndic = sorted(dic.items())

ans = 0
for i, v in ndic:
  if m <= v:
    ans += m * i
    break
  else:
    ans += v * i
    m -= v
print(ans)

Solution (Python):
N, M = map(int, input().split())
A_B = []
for i in range(N):
    A_B.append(list(map(int, input().split())))
A_B.sort()
sum = 0
money = 0
i = 0
while sum <= M and i < N:
    money += A_B[i][0] * A_B[i][1]
    sum += A_B[i][1]
    i += 1
money -= A_B[i-1][0] * (sum - M)
print(money)

Solution (Python):



import operator

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

stores = list()
for _ in range(N):
    stores.append( tuple(map(int, raw_input().split())) )

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

money = 0
cans_cnt = 0
for cost_i, cans_i in stores:
    buy_i = min(M - cans_cnt, cans_i)
    money += (cost_i * buy_i)
    cans_cnt += buy_i
    if (cans_cnt == M):
        break

print '{}'.format(money)

Solution (Python):
N,M = map(int,input().split())
AB = [0]*N
for i in range(N):
    AB[i] = list(map(int,input().split()))

AB = sorted(AB,key = lambda k:k[0])
yen =0
num =0
for j in range(N):
    num += AB[j][1]
    if num >= M:
        yen += (M - (num - AB[j][1])) * AB[j][0]
        break
    else:
        yen += AB[j][1]*AB[j][0]

print(yen)

Solution (Python):


import numpy

N,M=map(int, input().split())
price = numpy.empty((N,3))
sumcan = 0
sumprice = 0
lastshop = 0

for i in range(N):
    shop_data = input().split()
    A = int(shop_data[0])
    B = int(shop_data[1])
    price[i,0]= A * B
    price[i,1] = A
    price[i,2] = B

price = price[price[:,1].argsort(),:]

for j in range(M):
    sumcan = sumcan + price[j,2]
    if sumcan < M:
        sumprice = sumprice + price[j,0]
    elif sumcan >= M:
        sumcan = sumcan - price[j,2]
        lastshop = j
        break

sumprice = sumprice + (M - sumcan)*price[lastshop,1]

print(int(sumprice))

Solution (Python):
N,M = map(int, input().split())
A = []
quantity = 0
price = 0

for i in range(N):
    a = list(map(int, input().split()))
    A.append(a)
A = sorted(A)
for i in range(M):
    quantity += A[i][1]
    if quantity < M:
        price += A[i][0]*A[i][1]
    else:
       price += A[i][0]*(M-(quantity-A[i][1]))
       break
print(price)

Solution (Python):
N, M = map(int, raw_input().split())
ans = 0
list = [map(int , raw_input().split()) for n in range(N)]
list = sorted(list, key = lambda list: list[0])
cnt = 0
for n in range(N):
    A, B = list[n]
    for b in range(B):
        ans += A
        cnt += 1
        if cnt == M:
            print(ans)
            exit()

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

ab = []

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

ab.sort()

sum_size = 0
total = 0
for i in range(n):
    price = ab[i][0]
    size = ab[i][1]
    sum_size += size
    total += price*size
    if sum_size > m:
        total -= (sum_size-m)*price
        break
print(total)

Solution (Python):
N,M=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])

ans=0
quantity=0

for i in AB:
  if quantity+i[1] < M:
    ans += i[0]*i[1]
    quantity += i[1]
  else:
    ans += i[0]*(M-quantity)
    break

print(ans)

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

AB.sort(key=lambda x:x[0])
tmp = M
ans = 0

for i in range(N):
    
    if tmp <= AB[i][1]:
        ans += tmp * AB[i][0]
        break
    
    ans += AB[i][0] * AB[i][1]
    tmp = tmp - AB[i][1]


print(ans)

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

ans = 0





shop_list = []
for _ in range(N):
    hoge = {}
    A, B = map(int, input().split())
    hoge['price'] = A
    hoge['amount'] = B
    shop_list.append(hoge)
    hoge = {}

shop_list.sort(key=lambda x: x['price'])

quontity = 0
money = 0
for i in range(N):
    money += shop_list[i]['price']*shop_list[i]['amount']
    
    quontity += shop_list[i]['amount']
    
    if quontity >= M:
        money -= shop_list[i]['price']*(quontity-M)
        break

print(money)

Solution (Python):
from sys import stdin
import heapq
hq = []  

NM = input()
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

hq = []
AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])
  heapq.heappush(hq, (int(temp[0]), int(temp[1])))

cost = 0
amount = 0
for i in range(N):
  temp = heapq.heappop(hq)
  if amount + temp[1] < M:
    amount += temp[1]
    cost += temp[0]*temp[1]
  else:
    temp1 = M - amount
    cost += temp[0]*temp1
    break
    
print(cost)

Solution (Python):
N, M = map(int, input().split())
shop = []
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])
shop.sort(key=lambda x: x[0])

amount = 0
quantity = 0
for s in shop:
    if quantity + s[1] < M:
        amount += s[0] * s[1]
        quantity += s[1]
    else:
        amount += (M - quantity) * s[0]
        quantity = M
        break

print(amount)

Solution (Python):
import sys
input = sys.stdin.readline


if __name__ == '__main__':
    n, m = map(int, input().split())
    shops = []
    ans = 0
    for i in range(n):
        shops.append(list(map(int, input().split())))
    shops.sort(key=lambda x:x[0])

    for shop in shops:
        price = shop[0]
        available = shop[1]
        if m - available > 0:
            ans += price * available
            m -= available
        else:
            ans += price * m
            break

    print(ans)

Solution (Python):
N, M = map(int, input().split())
shop = []
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])
shop.sort(key=lambda x: x[0])

amount = 0
quantity = 0
for s in shop:
    if quantity + s[1] < M:
        amount += s[0] * s[1]
        quantity += s[1]
    else:
        amount += (M - quantity) * s[0]
        quantity = M
        break

print(amount)

Solution (Python):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort(key = lambda x: x[0])

total = 0
i = 0

while True:
    total += AB[i][1]
    if total < M:
        i += 1
    else:
        break

ans = 0
for j in range(i):
    ans += AB[j][0]*AB[j][1]
ans += (M - sum(AB[p][1] for p in range(0,i))) * AB[i][0]
print(ans)

Solution (Python):
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key = lambda x: x[0])
total = 0
i = 0
while True:
	total += ab[i][1]
	if total < m:
		i += 1
	else:
		break
ans = 0
for j in range(i):
	ans += ab[j][0] * ab[j][1]
ans += (m - sum(ab[p][1] for p in range(0,i))) * ab[i][0]
print(ans)

Solution (Python):
import sys;n,m=input().split();m=int(m);a=[];i=n=c=0;a=sorted(tuple(map(int,e.split()))for e in sys.stdin)
while m>0:c+=a[i][0]*a[i][1];m-=a[i][1];i+=1
print(c+m*a[~-i][0])

Solution (Python):
from collections import namedtuple

Shop = namedtuple('Shop', ('a', 'b'))

def main():
    n, m = map(int, input().split())
    shops = []
    for _ in range(n):
        a, b = map(int, input().split())
        shops.append(Shop(a, b))
    
    print(solve(shops, m))

def solve(shops, m):
    cost = 0
    count = 0

    for shop in sorted(shops):
        if count + shop.b >= m:
            cost += shop.a * (m - count)
            return cost
        
        count += shop.b
        cost += shop.a * shop.b

main()

Solution (Python):
N, M = list(map(int, input().split()))
A = {}
B = [0] * N
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))
A = sorted(A.items(), key=lambda x:x[1])

ans = 0

for i in range(N):
    if M > B[A[i][0]]:
        ans += A[i][1] * B[A[i][0]]
        M -= B[A[i][0]]
    else:
        ans += A[i][1] * M
        break;
print(ans)

Solution (Python):
N, M = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(N)])
drink = 0
cost = 0

for i in range(N):
    cost += shops[i][0]*shops[i][1]
    drink += shops[i][1]
    if drink >= M:
        cost -= (drink -M) * shops[i][0]
        break
        
print(cost)

Solution (Python):
n, m = map(int,input().split())
shops = sorted([list(map(int, input().split())) for i in range(n)])
buydrinks = 0
cost = 0

for i in range(n):
    cost += shops[i][0] * shops[i][1]
    buydrinks += shops[i][1]
    if buydrinks >= m:
        cost -= (buydrinks - m) * shops[i][0]
        break

print(cost)

Solution (Python):
N,M = map(int,input().split())
drink_dict = {}
for i in range(N):
  A,B = map(int,input().split())
  if A not in drink_dict:
  	drink_dict[A] = B
  else:
    drink_dict[A] += B 
drink_list = sorted(drink_dict.items())
total_number = 0
total_price = 0
for i in drink_list:
  if total_number + i[1] >= M:
    print(total_price + (M-total_number) * i[0])
    break;
  else:
    total_price+=i[0]*i[1]
    total_number+= i[1]

Solution (Python):
n,m,*t = map(int, open(0).read().split())
ans = 0
for a, b in sorted(zip(t[::2], t[1::2])):
  ans += min(b, m)*a
  m -= b
  if m <= 0:
    print(ans)
    break

Solution (Python):
import itertools

N, M  = tuple([int(x) for x in input().split(' ')])
AB = [tuple([int(x) for x in input().split(' ')]) for i in range(N)]

ans = 0
count = 0
for a, b in sorted(AB, key=lambda x: x[0]):
        if M - count <= b:
                ans +=  (M - count) * a
                break
        else:
                count += b
                ans += a * b

print(ans)

Solution (Python):


class Shop():
    def __init__(self, yen, num):
        self.yen = yen  
        self.num = num  


def solve():
    N, M = list(map(int, input().split(" ")))
    A, B = [], []
    shops = []
    for i in range(N):
        a, b = list(map(int, input().split(" ")))
        A.append(a)
        B.append(b)
        shops.append(Shop(a, b))
    
    shops = sorted(shops, key=lambda x: x.yen)

    ans = 0
    rest_count = M
    for i in range(N):
        if rest_count <= shops[i].num:
            ans += shops[i].yen * rest_count
            break
        ans += shops[i].yen * shops[i].num
        rest_count -= shops[i].num
    
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
n, m = map(int, input().split())
ab = [ [int(x) for x in input().split()] for _ in range(n) ]

ab.sort()

ans = 0

for (a, b) in ab:
    if m == 0:
        break
    for _ in range(b):
        if m == 0:
            break
        m -= 1
        ans += a

print(ans)

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

src.sort(key = lambda x:-x[0])
sum_pay = 0
while 1:
    a,b = src.pop()
    if m > b:
        sum_pay += a*b
        m -= b
    else:
        sum_pay += a*m
        break
print(sum_pay)

Solution (Python):
N,M=map(int,(input()).split())
List=[]
for i in range(1,N+1):
  AB=[int(j) for j in (input()).split()]
  List.append(AB)
List.sort()
S=0
P=0
k=0
while S<M:
  a=List[k][0]
  b=List[k][1]
  if S+b<=M:
    P=P+a*b
    S=S+b
  else:
    P=P+a*(M-S)
    S=M
  k=k+1
print(P)

Solution (Python):
N, M = map(int, input().split())
AB = []

for _ in range(N):
    AB_i = list(map(int, input().split()))
    AB.append(AB_i)
    
AB_sorted = sorted(AB)

num = 0
paied = 0

for AB_i in AB_sorted:
    a = AB_i[0]
    b = AB_i[1]
    
    paied += a * b
    num += b
    
    if num >= M:
        paied -= (num - M) * a
        break

print(paied)

Solution (Python):
from sys import stdin

N, M = map(int, stdin.readline().split())
arr = []
for i in range(N):
  arr.append(list(map(int, stdin.readline().split())))

arr.sort(key=lambda a: a[0])
ans = 0
index = 0
bought = 0
while True:
    p, q = arr[index]
    q = min(q, M - bought)

    ans += p * q
    bought += q

    if bought == M:
        break

    index += 1

print(ans)

Solution (Python):

n, m = map(int, input().split())
shops = []
for i in range(n):
    shops.append(list(map(int, input().split())))
shops = sorted(shops)

price = 0
i = 0
while m > 0:
    if m - shops[i][1] >= 0:
        price += shops[i][0] * shops[i][1]
        m -= shops[i][1]
        i += 1
    else:
        price += shops[i][0] * m
        m -= m
print(price)

Solution (Python):
N,M = map(int, input().split())
A_B=[]
for i in range(N):
  A_B.append(tuple(map(int, input().split())))
A_B.sort()
cnt = 0
m = 0
price = 0
while m < M:
  if A_B[cnt][1] > M-m:
    price += A_B[cnt][0]*(M-m)
    m = M
  else:
    price += A_B[cnt][0]*A_B[cnt][1]
    m += A_B[cnt][1]
  cnt += 1
print(price)

Solution (Python):
n,m=map(int, input().split())
shop=sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])

ans = 0
for (val,amo) in shop:
	if amo > m:
		ans += m * val
		break
	else:
		m -= amo
		ans += amo * val

print(ans)

Solution (Python):
N,M = [int(i) for i in input().split()]
shop_info = []
for i in range(N) :
    shop_info.append([int(i) for i in input().split()])


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

cost = 0
current_kan = 0
for info in shop_info:
    price = info[0]
    stock = info[1]
    if (current_kan + stock > M) :
        
        want_kan = M - current_kan 
        cost += price * want_kan
        break
    else :
        
        current_kan += stock
        cost += price * stock

print(cost)

Solution (Python):
N,M = map(int, input().split())
import numpy as np
AB = np.array([list(map(int, input().split())) for _ in range(N)])
idx = np.argsort(AB[:,0],axis=0)
AB = AB[idx]
l = []
for a,b in AB:
  l.extend([a]*b)
  if len(l) > M:
    break
print(sum(l[:M]))

Solution (Python):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]