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())
AB = []
count = 0
sum = 0

for i in range(N):
  a,b = map(int,input().split())
  s = [a,b]
  AB.append(s)
  
AB.sort()
i = 0
while(1):
  if(count >= M):
    break  
  if((count + AB[i][1]) <= M):
   sum += AB[i][0]*AB[i][1]
   count += AB[i][1]
  else:
    rest = M - count
    sum += AB[i][0]*rest
    break
  i += 1

print(sum)

Solution (Python):


n,m = map(int, input().split())
l=[]
for i in range(0,n):
  a,b = map(int, input().split())
  l.append([a,b])
l.sort()
r=0
nn=0
for i in range(0,n):
  if nn+l[i][1]>=m:
    r=r+l[i][0]*(m-nn)
    break
  else:
    nn=nn+l[i][1]
    r=r+l[i][0]*l[i][1]

print(r)

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

ans = 0
s = 0
for i in range(N):
    t = AB[i][1]
    c = min(M-s, t)
    ans += c*AB[i][0]
    s += c
    if s>=M: break

print(ans)

Solution (Python):
import numpy as np
n,m=map(int,input().split())
a=np.zeros(n)
b=np.zeros(n)
for i in range(n):
    a[i],b[i]=map(int,input().split())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    m-=b[x[i]]
    i+=1
print(int(ans))

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

sortAB = sorted(AB)

ans = 0
num = M
for i in sortAB:
    a,b = i
    if num >= b:
        num -= b
        ans += a* b
    else:
        ans += a * num
        break

print(ans)

Solution (Python):
N, M = map(int, input().split())
A = []
for i in range(N):
	A.append(list(map(int, input().split())))
A.sort()
count = 0
nedan = 0
for s in range(N):
	count += A[s][1]
	if(count < M):
		nedan += A[s][0]*A[s][1]
	elif(count >= M):
		nedan += A[s][0]*A[s][1]
		nedan -= A[s][0]*(count - M)
		print(nedan)
		exit()

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

drinkList.sort()
drinkCount = 0
money = 0

while drinkCount < M :
    for i in range(N) :
        if M - drinkCount > drinkList[i][1] :
            money += drinkList[i][0] * drinkList[i][1]
            drinkCount += drinkList[i][1]
        else :
            money += drinkList[i][0] * (M - drinkCount)
            drinkCount += M - drinkCount
            break

print(money)

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

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

money = 0
last = M
for s in shops:
    if s[1] <= last:
        money += s[0] * s[1]
        last -= s[1]
    else:
        money += s[0] * last
        break

print(money)

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

AB.sort()

rest=M
shop=0
money=0
while True:
    
    if AB[shop][1]<rest:
        money+=AB[shop][1]*AB[shop][0]
        rest-=AB[shop][1]
        shop+=1
    else:
        money+=AB[shop][0]*rest
        break

print(money)

Solution (Python):
in1 = list(map(int, input().split()))
N = in1[0]
M = in1[1]

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

A.sort()

req = 0

for a in A:
    if M <= a[1]:
        req += a[0]*M
        break

    req += a[0]*a[1]
    M -= a[1]

print(req)

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

arr.sort()
C=0
for i in range(N):
    if arr[i][1]<=M: 
        C+=arr[i][0]*arr[i][1]
        M-=arr[i][1]
    else:
        C+=arr[i][0]*M
        break
print(C)

Solution (Python):
import numpy as np
N, M=map(int, input().split(' '))
shops = []
for i in range(N):
    a, b = map(int, input().split(' '))
    shops.append([a,b])
shops =sorted(shops, key=lambda list: list[0])
n_bought = 0
p_bought = 0
i = 0
while n_bought < M:
    n = min(shops[i][1], M - n_bought)
    n_bought += n
    p_bought += shops[i][0]*n
    i += 1
print(p_bought)

Solution (Python):
import sys

class Shop:
  def __init__(self, A, B):
    self.price = A
    self.limit = B

def merge(a, b):
    """ Merge of two sorted arrays (iterative version)
    
    IN:  sorted arrays a and b
    OUT: merging of a and b into one sorted array
    """
    if not a or not b or a[-1].price < b[0].price:
        return a + b
    res = [ a[0] for i in range(len(a)+len(b)) ]
    next_a = 0
    last_a = len(a)-1
    last_b = len(b)-1
    for i in range(len(res)):
        next_b = i - next_a
        if (next_a > last_a) or ((next_b <= last_b) and (a[next_a].price > b[next_b].price)):
            res[i] = b[next_b]
        else:
            res[i] = a[next_a]
            next_a += 1
    return res


def mergeSort(array):
    """ Sorting function (merge sort)
    IN: arbitrary array
    OUT: sorted array
    """

    
    unit_length = 2
    array = [[i] for i in array]
    while len(array) != 1:
        temp = []
        len_arr = len(array)
        for i in range(0, len_arr, unit_length):
            if i == len_arr - 1:
                temp.append(array[i])
            else:
                temp.append(merge(array[i], array[i+1]))
        array = temp
    return array[0]
  

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

shop = a[0]
drink = a[1]

shops = []
for i in range(shop):
  a = list(map(int, input().split()))
  shops.append(Shop(a[0], a[1]))

shops = mergeSort(shops)

ans = 0
tmp = 0
for i in shops:
  B = i.limit
  if B > drink:
    tmp = drink
    drink = 0
  else:
    tmp = B
    drink -= B
  
  ans += i.price * tmp
  if drink == 0:
    break

print(ans)

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

sorted_items = sorted(
    ab,
    key=lambda x: x[0]
)
cost = 0
bought = 0
for c, stock in sorted_items:
    for s in range(1, stock + 1):
        bought += 1
        cost += c
        if bought == m:
            print(cost)
            exit()

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

Solution (Python):
N,M = map(int, input().split())
shop = list()
price = 0
item = 0
for i in range(N):
    shop.append(list(map(int, input().split())))
shop.sort()

for i in range(N):
    for _ in range(shop[i][1]):
        if(item >= M):
            break
        price += shop[i][0]
        item += 1

print(price)

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])
count = 0
ans = 0
for ab in AB:
    if M > count+ab[1]:
        count += ab[1]
        ans += ab[0]*ab[1]
    else:
        ans += ab[0] * (M-count)
        break
print(ans)

Solution (Python):
import sys

def main():
    inp = [[i for i in map(int, line.rstrip().split())] for line in sys.stdin.readlines()]
    rule = inp.pop(0)
    inp.sort(key=lambda x:x[0])
    n = 0
    temp = 0
    price = 0
    for i in inp:
        temp += i[1]
        if(rule[1] < temp):
            price += i[0] * (rule[1] - n)
            break
        n = temp
        price += i[0] * i[1]

    print(price)

if __name__ == '__main__':
    sys.exit(main())

Solution (Python):
import numpy as np
N,M = map(int,input().split())
AB=[]
for i in range(N):
    AB.append(list(map(int,input().split())))
ab = np.asanyarray(AB)
soto = list(np.argsort(ab[:,0]))
ans = 0
m = 0
for n in range(N):
  b = AB[soto[n]][1]
  a = AB[soto[n]][0]
  
  ans += min(M-m, b) * a
  m += min(M-m, b)
  
  if m == M:
    print(ans)
    exit()

Solution (Python):
import numpy as np

n, m = list(map(int, input().split()))

a = np.zeros(n, int)
b = np.zeros(n, int)

count = 0
v = 0

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

for i in a.argsort():
    if count + b[i] <= m:
        v += a[i] * b[i]
        count += b[i]
    else:
        v += a[i] * (m - count)
        break
print(v)

Solution (Python):
import numpy as np
n, m = map(int, input().split())

a = np.zeros((n,2))


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


aSorted = sorted(a, key=lambda ai: ai[0])

mc = 0
ans = 0
for ai, bi in aSorted:
    if mc + bi <= m:
        mc += bi
        ans += bi * ai
    else:
        mm = m - mc
        ans += mm * ai
        break
print(int(ans))

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

store_list = []
min_cost = 0

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

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

for sl in store_list:
    if M - sl[1] >= 0:
        min_cost += sl[0]*sl[1]
        M = M - sl[1]
    else:
        min_cost += sl[0]*M
        break

print(min_cost)

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())

n,m= (int(i) for i in input().split())       









b = []
a = []
for i in range(n):
    c,d = (int(i) for i in input().split())
    a.append([c,d])
a.sort(key=lambda x:(x[0]))
s = 0
sp = 0
for i in range(n):
  
    add = a[i][1]
    addprice = a[i][0]
    if s+add>=m:
        amo  = m-s
        s+=amo
        sp+=(addprice*amo)
 
    else:
        s+=add
        sp+=(add*addprice)
    if m<=s: break
print(sp)


"""
while m>s:
    minpos = a.index(min(set(a)))
    if s+b[minpos]>=m:
        amo = m-s
  
        s+=amo
        sp+=(a[minpos]*amo)
 
 
    else:
        s+=b[minpos]
        sp+=(a[minpos]*b[minpos])
        a.pop(minpos)
        b.pop(minpos)

 
print(sp)
"""

Solution (Python):
N, M = map(int, input().split())
shop_list = []
for i in range(N):
    A, B = map(int, input().split())
    shop_list.append([A,B])
shop_list.sort()    
sum_money = 0
bought_m = 0

for shop in shop_list:
    for i in range(shop[1]):
        if bought_m == M:
            print(sum_money)
            exit()
        bought_m += 1
        sum_money += shop[0]
if bought_m == M:
	print(sum_money)

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

l = []

for i in range(n):
    l.append(list(map(int, input().split())))
l.sort(key=lambda x:x[0])


cnt = 0
money = 0
while cnt < m:
    for temp in l:
        if cnt > m:
            break
        for _ in range(temp[1]):
            cnt = cnt + 1
            if cnt <= m:
                money = money + temp[0]
            else:
                break

print(money)

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

count = 0
money = 0
while True:
    count += ab[0][1]
    if count < m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)

Solution (Python):
N, M = (int(i) for i in input().split())

shop_list = []
for i in range(N):
  shop = [int(i) for i in input().split()] 
  shop_list.append(shop)

shop_list.sort()

money = 0
while(M > 0):
  for shop in shop_list:
    if M > shop[1]:
      money += shop[0] * shop[1]
      M -= shop[1]
    else:
      money += shop[0] * M
      M = 0

print(money)

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

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

    L.append([a,b])

L= sorted(L)

for i in range(N):

    if M < L[i][1]:
        ans=L[i][0]*M

        print(ans)
        exit()
        
    else:
        ans += L[i][0]*L[i][1]
        M -= L[i][1]

        if M==0:

            print(ans)
            exit()

        elif M <= L[i+1][1]:

            ans += M * L[i+1][0]
            print(ans)
            exit()

Solution (Python):
N,M=map(int,input().split())
ab_dic={}
for i in range(N):
    a,b=list(map(int, input().split()))
    if a in ab_dic.keys():
        ab_dic[a]+=b
    else:
        ab_dic[a]=b

ab_dic=sorted(ab_dic.items())
want=M
cout=0
money=0

while want>0:
    if ab_dic[cout][1]<want:
        money+=ab_dic[cout][0]*ab_dic[cout][1]
        want-=ab_dic[cout][1]
    else:
        money+=ab_dic[cout][0]*want
        break
    cout+=1
print(money)

Solution (Python):
str_l = input().split()
n = int(str_l[0])
m = int(str_l[1])
data = []
for i in range(0, n):
    str_l = input().split()
    a = int(str_l[0])
    b = int(str_l[1])
    data.append([a, b])
data.sort(key = lambda x: x[0])
sum = 0
cost = 0
for i in range(0, n):
    if sum + data[i][1] <= m:
        sum = sum + data[i][1]
        cost = cost + data[i][0] * data[i][1]
    else:
        cost = cost + (m - sum) * data[i][0]
        break
print(cost)

Solution (Python):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort(key=lambda x:x[0])
ans=0
for i in range(n):
  s,t=l[i]
  if m-t<=0:
    ans+=s*m
    break
  else:
    m-=t
    ans+=s*t
print(ans)

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

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

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

Solution (Python):
from operator import itemgetter
N,M = map(int, input().split())

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

l.sort(key=itemgetter(0))
sum = 0
for i in range(len(l)):
    a,b = map(int, l[i])
    if M - b >= 0:
        sum += a * b
        M -= b
    else:
        sum += a * M
        M = 0

    if M == 0:
        break

print(sum)

Solution (Python):
import numpy as np
n, m = map(int, input().split())
f = lambda:list(map(int, input().split()))
arr = np.zeros((n,2),'i8')

Q = m
price = 0

for i in range(n):
  p, q = f()
  
  arr[i] = (p,q)
arr = sorted(arr.tolist())

while Q>0:
  for i in range(n):
    p = arr[i][0]
    q = arr[i][1]
    if q > Q:
      q = Q
      price += p*q
      
      Q -= q
    else:
      price += p*q
      
      Q -= q
  
print(price)

Solution (Python):
from numpy import argsort
n, m = map(int, input().split())
a=[]
b=[]
for i in range(n):
    ab=list(map(int, input().split()))
    a.append(ab[0])
    b.append(ab[1])

total_cost = 0
order = argsort(a)
for i in range(len(a)):
    new_shop = order[i]
    new_drinks = b[new_shop]
    if m-new_drinks>0:
        total_cost = total_cost + a[new_shop] * b[new_shop]
        m=m-new_drinks
    else:
        total_cost = total_cost + a[new_shop] * m
        break
print(total_cost)

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

grid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)

grid.sort()

kosu = 0
price = 0
for i in range(N):
    if kosu == M:
        break
    elif kosu+grid[i][1] < M:
        kosu = kosu + grid[i][1]
        price = price + grid[i][0]*grid[i][1]
    else:
        price = price + (M-kosu)*grid[i][0]
        break

print(price)

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

mises.sort()
pay=0
for i in mises:
    if i[1]<M:
        pay+=i[0]*i[1]
        M-=i[1]
    else:
        pay+=i[0]*M
        break
print(pay)

Solution (Python):
from collections import OrderedDict

N, M = [int(x) for x in input().split()]
AB = sorted([[int(x) for x in input().split()] for _ in range(N)], key=lambda x: x[0])

y = 0
for ab in AB:
    n = min(ab[1], M)
    y += ab[0] * n
    M -= n

    if M == 0:
        break
print(y)

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

def calc(li, m):
    total = 0
    for sh in li:
        if sh[1] < m:
            total += sh[0] * sh[1]
            m -= sh[1]
        else:
            total += sh[0] * m
            return total

print(calc(sh_li, M))

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

money = 0
count = 0
A_B = sorted(A_B)
while count < M:
    if count+A_B[0][1] <= M:
        count += A_B[0][1]
        money += A_B[0][0] * A_B[0][1]
    else:
        money += A_B[0][0] * (M-count)
        count = M
    A_B.pop(0)
print(money)

Solution (Python):
N,M=map(int, input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
AB.sort()
count=0
summary=0
for i in range(N):
  for j in range(AB[i][1]):
    summary+=AB[i][0]
    count+=1
    if count==M:
      print(summary)
      break
  else:
    continue
  break

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

ab = [0]*N

for i in range(N):
    ab[i]=input().rstrip().split()

for i in range(N):
    ab[i][0]=int(ab[i][0])
    ab[i][1]=int(ab[i][1])

ab = sorted(ab)

sum = 0
sum_money = 0
for i in range(N):
    if sum + ab[i][1]< M:
        sum += ab[i][1] 
        sum_money += ab[i][1]*ab[i][0]
    else:
        while(sum!=M):
            sum_money += ab[i][0]
            sum += 1




print(sum_money)

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

kane = 0
count = 0

l.sort()

for i in range(N):
    if count + l[i][1] >= M:
        kane += l[i][0]*(M-count)
        break
    else:
        count += l[i][1]
        kane += l[i][0] * l[i][1]

print(kane)

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

ab_dict = dict()
for i in range(N):
    a, b = map(int, raw_input().split())
    if a in ab_dict:
      ab_dict[a] += b
    else:
      ab_dict[a] = b

answer = 0
for a in sorted(ab_dict.keys()):
    b = ab_dict[a]
    if M <= b:
        answer += a * M
        break
    else:
        answer += a * b
        M -= b

print(answer)

Solution (Python):
N,M=map(int,input().split())
data=[]
for _ in range(N):
    a,b=map(int,input().split())
    data.append((a,b))
data.sort()
count=0
index=0
sum=0
while count<M:
    sum+=data[index][0]*data[index][1]
    count+=data[index][1]
    index+=1

index+=-1

sum=sum-data[index][0]*(count-M)

print(sum)

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])
A = []
B = []
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])

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

print(ans)

Solution (Python):
N,M = map(int,input().split())
A = [0] * N
B = [0] * N
C = [[0,0] for i in range(N)]
check = 0
money = 0
a = 0
k = 0

for i in range(N):

    A[i],B[i] = map(int,input().split())
    C[i] = [A[i],B[i]]

C.sort()

while a == 0:

    if check + C[k][1] < M:

        check += C[k][1]
        money += C[k][0]*C[k][1]
        k += 1

        
    else:

        money += C[k][0] * (M-check)
        a += 1

print(money)

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

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

price = 0
m = M
for a, b in S:
    if m <= b:
        price += m * a
        m = 0
    else:
        price += a * b
        m = m - b
    
    if m <= 0:
        break
    
print(price)

Solution (Python):
N, M = map(int, input().split())
shop = list()
for i in range(N):
    li = list(map(int, input().split()))
    shop.append(li)

shop.sort()

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

print(ans)

Solution (Python):
n,m=map(int,input().split())
c={}
d=[]
for i in range(n):
  a,b=map(int,input().split())
  if a not in c:
    c[a]=0
    d.append(a)
  c[a]+=b
  
d.sort()

ans=0
for i in range(n):
  if m > c[d[i]]:
    m-=c[d[i]]
    ans+=d[i]*c[d[i]]
  else:
    ans+=d[i]*m
    break
    
print(ans)

Solution (Python):
n,m=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
acsd=sorted(ab,key=lambda a:a[0])
yen_tot=0
n_b=m
def count_p(store,n_v):
    yen,num=store
    return yen*min(n_v,num),max(n_v-num,0)
for s in acsd:
    cost,rem=count_p(s,n_b)
    yen_tot+=cost
    n_b=rem
    if rem==0: break
print(yen_tot)

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

yen = 0
for i in p:
    if m == 0:
        break
    if m < i[1]:
        yen+=m*i[0]
        break
    else:
        yen+=i[0]*i[1]
        m -= i[1]
print(yen)

Solution (Python):
import numpy as np

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

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

A = np.array(A)
cheep_sort = A.argsort()

ans = 0
cnt = 0
for i in cheep_sort:
    if cnt + B[i] > M:
        ans += A[i] * (M - cnt)
        break
    else:
        ans += A[i] * B[i]
        cnt += B[i]

print(ans)

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

sum=0
k=0

for j in range(m):
    if(b[k][1]==0):
        k+=1
    sum+=b[k][0]
    b[k][1]-=1

print(sum)

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

sortedLi = sorted(li, key=lambda x:(x[0], x[1]))

num = 0
ans = 0
for AB in sortedLi:
    if num + AB[1] >= M:
        ans += (M - num) * AB[0]
        break
    else:
        num += AB[1]
        ans += AB[1] * AB[0]

print(ans)

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

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

count = 0
for i in range(len(AB_array_s)):
    A,B = AB_array_s[i]
    if M <= B:
        count += A * M
        break
    else:
        M -= B
        count += A * B

print(count)

Solution (Python):


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

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

ans = 0
m = M
for a, b in A:
    if m <= b:
        ans += m*a
        break
    else:
        ans += b*a
        m -= b

print(ans)

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

Solution (Python):
from sys import stdin
import numpy as np
N,M=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
data=sorted(data)
ans=0
cnt=0
for j in data:
    cnt+=j[1]
    ans+=j[0]*j[1]
    if cnt >= M:
        ans=ans-(cnt-M)*j[0]
        break
print(ans)

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

store = []
for _ in range(N):
    A, B = [int(i) for i in input().split()]
    store.append((A, B))

store = sorted(store, key=lambda s: s[0])
number, price = 0, 0

for a, b in store:
    if M - (number + b) > 0:
        number += b
        price += a * b
    else:
        price += (M - number) * a
        break

print(price)

Solution (Python):
import sys

l = raw_input().split()
N = int(l[0])
M = int(l[1])

AB = [[0 for i in range(2)] for j in range(N)]

for n in range(N):
    l = raw_input().split()
    AB[n][0] = int(l[0])
    AB[n][1] = int(l[1])

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


sum = 0
drinks = 0
for n in range(N):
    a = ab[n]
    if drinks + a[1] < M:
        sum += a[0] * a[1]
        drinks += a[1]
    else:
        num = M - drinks
        sum += a[0] * num
        drinks += num
        break

print(sum)

Solution (Python):
from collections import Counter
n,m=map(int,input().split())
ls=[list(map(int,input().split())) for i in range(n)]
ls.sort(key=lambda x:x[0])
ans=0
tmp=0

for i in range(len(ls)):
  if tmp+ls[i][1]<=m:
    tmp+=ls[i][1]
    ans+=ls[i][0]*ls[i][1]
  else:
    ans+=ls[i][0]*(m-tmp)
    print(ans)
    exit()
print(ans)

Solution (Python):
from operator import itemgetter

n, m = map(int, input().split())
store = [] 
cart, price = 0, 0

for _ in range(n):
    temporary_dict = {}
    a, b = map(int, input().split())
    temporary_dict["value"] = a
    temporary_dict["stock"] = b
    store.append(temporary_dict)

store.sort(key=itemgetter("value", "stock"))

for i in range(n):
    test_value = store[i]["value"]
    test_stock = store[i]["stock"]
    if test_stock < m:
        m -= test_stock
        price += test_value*test_stock
    else:
        price += test_value*m
        break

print(price)

Solution (Python):
from operator import itemgetter

n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
ans = 0
a.sort(key=itemgetter(0))
i = 0
while(1):
    if m == 0:
        break
    if a[i][1] <= m:
        ans += a[i][0]*a[i][1]
        m -= a[i][1]
        i += 1
    else:
        ans += a[i][0]*m
        m = 0
print(ans)

Solution (Python):
a, b = map(int, input().split())

A = []

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

ans = 0

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


for j in range(a+1):
    if(b - A[j][1] >=0):
        ans += A[j][0] * A[j][1]
        b -= A[j][1]
    else:
        ans += A[j][0] * b
        b = 0
    if(b == 0):
        break
    
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return list(map(int, input().split()))
def getList():
    return list(map(int, input().split()))

n,m = getNM()
stores = []
for i in range(n):
    stores.append(getNM())

stores.sort()
ans = 0
for store in stores:
    if m <= store[1]:
        ans += store[0]* m
        break
    else:
        ans += store[0]*store[1]
        m -= store[1]


print(ans)

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

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

sortedList= sorted(drinkList)

need = m
count = 0
for i in range (n):
  if(need >= sortedList[i][1]):
    need-= sortedList[i][1]
    count+= sortedList[i][0]*sortedList[i][1]
  else:
    count+= sortedList[i][0]*need
    break

print(count)

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

num = 0
tot = 0
for i in range(N):
    c = min(price[i][1], M - num)
    num += c
    tot += c*price[i][0]
    if(num == M): break
print(tot)

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

n = 0
result = 0

while M > 0:
    if AB[n][1] <= M:
        result += AB[n][0] * AB[n][1]
        M -= AB[n][1]
        n += 1
    else:
        result += AB[n][0] * M
        break

print(result)

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
list1 = list()
for i in range(N):
  list1.append(list(int(x) for x in input().split()))
list1.sort(key=itemgetter(0))
ans = 0
j = 0
while True:
  if M > list1[j][1]:
    ans += list1[j][0] * list1[j][1]
    M -= list1[j][1]
    j += 1
  else:
    ans += list1[j][0] * M
    print(ans)
    exit()

Solution (Python):
from operator import itemgetter

N, M = map(int,input().split())
shops = []
for i in range(N):
  shops.append(list(map(int,input().split())))
shops.sort(key=itemgetter(0))
daikin = 0
can = 0
j = 0
while can < M:
  daikin += (shops[j][0]*shops[j][1])
  can += shops[j][1]
  j += 1
if can > M:
  daikin -= (can - M)*shops[j-1][0]
print(daikin)

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

for i in range(n):
  a = data[i][0]
  b = data[i][1]
  c = 0
  while b > 0:
    if m <= 0:
      break
    m -= 1
    b -= 1
    c += 1
    
  res += a * c
print(res)

Solution (Python):
n,m=map(int,input().split())
drk=[list(map(int,input().split())) for _ in range(n)]
drk.sort()
i=0
ans=0

while m>0:
  a,b=drk[i]
  if m>=b:
    ans+=a*b
    m=m-b
  else:
    ans+=a*m
    m=0
  i+=1
  
print(ans)

Solution (Python):
from operator import itemgetter
n, m = map(int, input().split())
a = []
ans = 0
many = m
for i in range(n):
    a.append(list(map(int, input().split())))
a.sort(key=itemgetter(0))
for i in range(m):
    if a[i][1] < many:
        ans += (a[i][0])*(a[i][1])
        many = many-a[i][1]
    else:
        ans += a[i][0]*many
        print(ans)
        break

Solution (Python):
rr = lambda: input().strip()
rrm = lambda: list(map(int, rr().split()))

N, M = rrm()
drinks = [rrm() for _ in range(N)]


drinks.sort()
cost = 0
for A, B in drinks:
    buy = min(B, M)
    M -= buy
    cost += buy * A
    if M == 0: break
print(cost)

Solution (Python):
import bisect

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

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

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

def func():
    c=0
    ans=0

    for target in ab:
        for i in range(target[1]):
            ans+=target[0]
            c+=1

            if c == m:
                return ans
            

print(func())

Solution (Python):
[n, m] = [int(i) for i in input().split()]
lists = [[int(j) for j in input().split()] for i in range(0, n)]
price = {}
bottle = {}

for (idx, [a, b]) in enumerate(lists):
    price[idx] = a
    bottle[idx] = b

total = 0
bought = 0
for k, v in sorted(price.items(), key=lambda x: x[1]):
    if m > bottle[k]:
        bought = bought + bottle[k]
        total = total + price[k] * bottle[k]
        m = m - bottle[k]
    else:
        total = total + price[k] * m
        break

print(total)

Solution (Python):
n, m = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
ans = 0
for x in li:
    ans += x[0]*min(m, x[1])
    m -= min(m, x[1])
print(ans)