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())
A = [[] for _ in range(N)]
B = [[] for _ in range(N)]
lst = []
for i in range(N):
    A[i], B[i] = map(int, input().split())
    lst.append([A[i],B[i]])

lst.sort()

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

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

def calc(AB):
    cnt = 0
    yen = 0
    for n in AB:
        for i in range(n[1]):
            cnt += 1
            yen += n[0]
            if M == cnt:
                return yen

print(calc(AB))

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

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

lst.sort()
price = 0


for A, B in lst:
    if M == 0:
        break
    for i in range(B):
        price += A
        M -= 1
        if M == 0:
            break

print(price)

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

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

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

shop_list = sorted(shops_n_limit, key=lambda x: x[0])
cost = 0
num = 0
num_shop = 0
for i, shop in enumerate(shop_list):
    if num >= M:
        break
    cost += shop[0] * shop[1]
    num += shop[1]
    num_shop = i

if num != M:
    cost -= shop_list[num_shop][0] * shop_list[num_shop][1]
    num -= shop_list[num_shop][1]
    while num != M:
        cost += shop_list[num_shop][0]
        num += 1

print(cost)

Solution (Python):
import numpy as np

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

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

S = np.array(S)

S = S[np.argsort(S[:, 0])]

count = 0
yen = 0
for s in S:
    if count + s[1] < M:
        yen += s[0] * s[1]
        count += s[1]
    else:
        yen += s[0] * (M-count)
        break

print(yen)

Solution (Python):


"""
Created on 2019/3/9
Solved on 2019/3/9
@author: shinjisu
"""






def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**12


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def prob_C():
    N, M = getIntList()
    dmp((N, M))
    BA = zeros(N)
    for i in range(N):
        BA[i] = getIntList()
    dmp(BA, 'BA')
    BA.sort()
    dmp(BA, 'BA')
    count = 0
    yen = 0
    for i in range(N):
        buyCount = min(BA[i][1], M-count)
        yen += buyCount * BA[i][0]
        count += buyCount
        dmp((buyCount, count, yen), 'buyCount, count, yen')
        if buyCount >= M:
            break
    dmp(yen, 'yen')
    return yen


debug = False  
ans = prob_C()
print(ans)

Solution (Python):

import copy
import numpy as np
import random

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

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







shops.sort()
ans = 0
count = m

i = 0
while True:
    
    yen,num = shops[i]
    if count-num > 0:
        count -= num
        ans += yen*num
        
        i += 1
    else:
        ans += yen*count
        
        count -= count
        break


print(ans)

Solution (Python):
N,M = map(int,input().split())
retails = []
for i in range(N):
    A,B = map(int,input().split())
    retails.append([A,B])
retails = sorted(retails)
purchase_price = 0
for retail in retails:
    if M > 0:
        if retail[1] >= M:
            purchase_price += retail[0] * M
            M = 0
        else:
            purchase_price += retail[0] * retail[1]
            M -= retail[1]
print(purchase_price)

Solution (Python):
import numpy as np

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

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

A = np.array(A, dtype=np.float64)
A = A[np.argsort(A[:, 0])]

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

print(int(ans))

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

count = 0
price = 0

for i in range(len(l)):
    if count + l[i][1] <= m:
        price += l[i][0] * l[i][1]
        count += l[i][1]
    elif count < m:
        price += (m - count) * l[i][0]
        break
print(price)

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

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

sum_num = 0
for a, b in AB:
    c = min(b, M)
    sum_num += a*c
    
    M -= c
    if M <= 0:
        break

print(sum_num)

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

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

p = M
ans = 0
for c in A:
    if c[1] >= p:
        ans += c[0] * p
        break
    ans += c[0] * c[1]
    p -= c[1]
print(ans)

Solution (Python):




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

listA =[]

for i in range(N):
    listA.append(list(map(int, input().split())))

money = 0
listA = sorted(listA)

for i in range(len(listA)):
    if M == 0:
        break

    if listA[i][1] > M:
        money += listA[i][0] * M
        M = 0
    else:
        M -= listA[i][1]
        money += listA[i][0] * listA[i][1]

print(money)

Solution (Python):
def answer():
    N, M = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    ab.sort()
    count = 0
    price = 0
    tmp = 0
    
    while(1):
        if count >= M:
            return price

        else:
            if ab[tmp][1] >=1:
                price += ab[tmp][0]
                ab[tmp][1] -= 1
                count += 1
            else:
                tmp += 1
                price += ab[tmp][0]
                ab[tmp][1] -= 1
                count += 1

print(answer())

Solution (Python):
import sys
import bisect
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())

categories = [ tuple(li()) for _ in range(N) ]
categories.sort()

total_cost = [(0, 0)]
for A, B in categories:
    total_cost.append((B + total_cost[-1][0], A * B + total_cost[-1][1]))
    idx = bisect.bisect_right( total_cost, (M, 0) )
total = total_cost[idx][1] + (M - total_cost[idx][0]) * categories[idx - 1][0]
print(total)

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

def foo():
  total = 0
  n = 0
  for e in hoge:
    for i in range(e[1]):
      total += e[0]
      n += 1
      if n >= M:
        return total
  return 0

print(foo())

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

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

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

print(ans)

Solution (Python):
import numpy as np
n, m = (int(i) for i in input().split())
a = [0]*n
b = [0]*n
for j in range(n):
    a[j], b[j] = (int(i) for i in input().split())
price = 0
for i in np.argsort(a):
    num = min(m, b[i])
    price = price + num * a[i]
    m = m - num
    if m == 0:
        break
print(price)

Solution (Python):
import numpy as np
N,M = map(int, input().split())
As, Bs = [], []
Cs = np.zeros((N,2))
for i in range(N):
    A, B = map(int, input().split())
    Cs[i] = [A,B]

C_sorted = Cs[Cs[:,0].argsort(), :]
value = 0
for a,b in C_sorted:
    M_tmp = M - b
    if M_tmp > 0:
        value += a*b
        M = M_tmp
    else:
        value += a*M
        break

print(int(value))

Solution (Python):
N,M = map(int, input().split(" "))
drink = []
for i in range(N):
  A,B = input().split(" ")
  drink.append([int(A), int(B)])

drink.sort()
cost = 0

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

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

drink = []
sum = 0
count = 0

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

drink.sort()


for d in drink:
    if count >= M:
            break
    for i in range(d[1]):
        sum += d[0]
        count += 1
        if count >= M:
            break

print(sum)

Solution (Python):
import numpy as np
import sys

def debug(*args, **kwargs):
    sys.stderr.write(*args, **kwargs)

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

A = np.zeros(N, dtype=np.int)
B = np.zeros(N, dtype=np.int)

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

all_sum = B.sum()

arg_sorted = np.argsort(A)

sum_amount = 0
sum_money = 0
to_break = False

for i in arg_sorted:
    if B[i] > M-sum_amount:
        to_break = True
    lot = min(B[i], M-sum_amount)

    sum_money += A[i]*lot
    sum_amount += lot
    

    if to_break:
        break


print(sum_money)

Solution (Python):
def solver(n, m, ab_list):
    ab_list = sorted(ab_list, key=lambda ab:ab[0])
    ans = 0
    for ab in ab_list:
        if (m > ab[1]):
            m -= ab[1]
            ans += ab[0] * ab[1]
        else:
            ans += ab[0] * m
            return ans


if __name__ == '__main__':

    n, m = map(int, input().split())
    ab_list = []
    for _ in range(n):
        ab_list.append(list(map(int, input().split())))

    ans = solver(n, m, ab_list)
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N,M=[int(x) for x in input().strip().split()]
AN=[]
BN=[]
val={}
for i in range(N):
    Ai,Bi=[int(x) for x in input().strip().split()]
    val[Ai]=Bi+val.get(Ai,0)
    AN.append(Ai)

AN=sorted(set(AN))
m=0
ans=0
for Ai in AN:
    ans+=Ai*min(M-m,val[Ai])
    m+=min(M-m,val[Ai])
    if m==M:
        break
print(ans)

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

temp = M

money = 0
for ab in lst:
	
	if ab[1] < temp:
		temp -= ab[1]
		money += (ab[0] * ab[1])
	else: 
		money += (temp * ab[0])
		break

print(money)

Solution (Python):
n,m = map(int,input().split())
a = []
[a.append(list(map(int,input().split()))) for _ in range(n)]
a.sort(key=lambda x:x[0])
price, hon, max_hon = 0, 0, 0
for i in a:
    max_hon+=i[1]
    if max_hon > m:
        break
    else:
        price+=i[0]*i[1]
        hon+=i[1]
print(price + i[0]*(m - hon))

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

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

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

count = m
money = 0
for shop in sorted_shop:
	if count == 0:
		break
	if count >= shop[1]:
		count = count - shop[1]
		money += shop[0] * shop[1]
	else:
		money += shop[0] * count
		count = 0

print(money)

Solution (Python):
n, m = map(int, input().split())
ts = sorted((tuple(map(int, input().split()))) for _ in range(n))
res = 0
for a, b in ts:
    x = min(b, m)
    res += a * x
    m -= x
print(res)

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

price=0


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

Li.sort()


i=0

while M>0:
	if Li[i][1] > M:
		price=price+Li[i][0]*M
		M=M-M
		i=i+1
	else:
		price=price+Li[i][0]*Li[i][1]
		M=M-Li[i][1]
		i=i+1

print(price)

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

AB = sorted(AB)

count = 0
result = 0
i = 0
while M != count:
    if 0 < AB[i][1]:
        result += AB[i][0]
        count += 1
        AB[i][1] -= 1
    else:
        i += 1
print(result)

Solution (Python):
N, M = input().split()
N = int(N)
M = int(M)
x = []
for i in range(N):
    a, b = input().split()
    x.append((float(a), float(b)))
x = sorted(x)
ans = float(0)
for i in x:
    if M >= i[1]:
        ans += i[1] * i[0]
        M -= int(i[1])
    else:
        ans += M * i[0]
        break
print(int(ans))

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

i=0
cost=0
while(1):
    if M-a[i][1]>0:
        M-=a[i][1]
        cost+=a[i][0]*a[i][1]
        i+=1
    else:
        cost+=M*a[i][0]
        break
print(cost)

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

li=[]
while True:
    try:
        li.append(list(map(int,input().split())))

    except:
        break;
      
li.sort()



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

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

for _ in range(n):
    aa,bb=map(int,input().split())
    ab.append((aa,bb))

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

ans=0
sums=0

for c in ab:
    sums+=min(c[1],m)
    ans+=min(c[1],m)*c[0]
    m-=c[1]
    if m <= 0:
        print(ans)
        exit()

Solution (Python):
import numpy as np

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

cost = [0]*N

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

    cost[i] = (a,b)

cost = sorted(cost,key=lambda x:x[0])
i = 0
cnt =0
money = 0

while cnt < M:
    a,b= cost[i]

    tmp = min(M - cnt,b)
    cnt += tmp
    money += a*tmp
    i += 1


print(money)

Solution (Python):

"""
Created on Sun Mar  3 20:59:27 2019

@author: doppe
"""
N, M = map(int, input().split())
listA = []
listB = []

for i in range (0, N):
    A, B = map(int, input().split())
    listA.append(A)
    listB.append(B)

li2 = sorted(range(len(listA)), key=lambda k: listA[k])

count = 0
cost = 0
for i in li2:
    if listB[i] + count > M:
        cost += (M - count) * listA[i]
        break
    else:
        cost += listA[i] * listB[i]
        count += listB[i]
print(cost)

Solution (Python):
NM = list(map(int,input().strip().split()))
N = NM[0]
M = NM[1]
ABs = []
for i in range(0,N):
    AB =list(map(int,input().strip().split()))
    ABs.append(AB)

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

ene_num = 0
cost = 0
for ab in ABs:
    nums = min(ab[1], M)
    cost += ab[0] * nums
    M -= nums
    if M <= 0:
        break


print(cost)

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

flag = 0
ans = 0
for i,j in enumerate(check):
    flag += j[1] 
    ans += j[0] * j[1]
    if flag >= M:
        print(ans -  check[i][0] * (flag - M))
        break

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

C = []

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

C.sort()

k = 0
ans = 0

for i in range(N):
    if k + C[i][1] <= M:
        k += C[i][1]
        ans += C[i][0] * C[i][1]
    
    else:
        ans += (M - k) * C[i][0]
        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 = sorted(AB, reverse=False)

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

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

money = 0
items = 0
for i in range(N):
    if (items + AB[i][1] < M):
        money += AB[i][0] * AB[i][1]
        items += AB[i][1]
    else:
        j = (M - items)
        money += AB[i][0] * j
        items +=j
        
        
        
        

print(money)

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

ab.sort()
t = m
a = 0
for i in ab:
    if(i[1] <=t):
        t = t - i[1]
        a = a + i[0] * i[1]
    else:
        a = a + i[0] * (t)
        t = 0

    if(t <= 0):
        break
print(a)

Solution (Python):
import numpy as np
N,M = map(int,input().split())
AB_list = np.array([list(map(int,input().split())) for _ in range(N)])

cheapStore = np.argsort(AB_list[:,0])
ans = 0
need = M
store = 0
while need > 0:
    store_num = cheapStore[store]
    drink_num = AB_list[store_num][1]
    drink_cost = AB_list[store_num][0]
    if need>=drink_num:
        ans += drink_num * drink_cost
        need -= drink_num
    else:
        ans += need * drink_cost
        need = 0
    store += 1
        
print(ans)

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

remained = M
cost = 0
shops = sorted(shops, key=lambda x: x[0])
for s in shops:
    cost += min(s[1], remained) * s[0]
    remained -= s[1]
    if remained <= 0:
        break
print(cost)

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

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

counter=0
i=0
ans=0
while counter < m:
    counter+=l[i][1]
    i+=1

for k in range(i):
    ans+=l[k][0]*l[k][1]


if counter>m:
    ans-=l[k][0]*(counter-m)
print ans

Solution (Python):
def main():

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

  pairs = []
  for _ in range(N):
    a, b = map(int, input().split(' '))
    pairs.append([a, b])
  

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

  yen = 0
  count = 0
  
  for a, b in pairs:
    if count >= M:
      
      break

    for mo in range(b):
      count += 1
      yen += a
      
      if count >= M:
        
        break
  print(yen)

main()

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

d = 0
answer = 0
for i in range(n):
    a, b = c[i]
    if d + b < m:
        d += b
        answer += a * b
    else:
        answer += a * (m - d)
        break
print(answer)

Solution (Python):
import numpy as np
 
n, m = map(int, input().split(' '))
a = []; b = []
for nn in range(n):
    ls = list(map(int, input().split(' ')))
    a.append(ls[0])
    b.append(ls[1])

a = np.array(a)
b = np.array(b)

ind = np.argsort(a)
a = a[ind]
b = b[ind]
    
amount = 0
count = 0
for i in range(len(a)):
    amount += min(b[i], m - count) * a[i]
    count += b[i]
    if count >= m:
        break
 
print(amount)

Solution (Python):
l= input().split(" ")
n = int(l[0])
m = int(l[1])
shops = []
money =0
for i in range(n):
    shop = input().split(" ")
    shop[0]=int(shop[0])
    shop[1]=int(shop[1])
    shops.append(shop)
shops.sort()
for i in range(n):
    if(m>shops[i][1]):
        m = m- shops[i][1]
        money = money + shops[i][1]*shops[i][0]
    else:
        money = money + m*shops[i][0]
        break
print(money)

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

ans = 0
for AB in lst_AB:
    A, B = AB[0], AB[1]
    if M >= B:
        ans += A*B
        M -= B
    else:
        ans += A*M
        M -= M
print(ans)

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

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

A = np.array(A)
B = np.array(B)

argsort = np.argsort(A)

count = M
yen = 0
loop_index = -1
while(count>0):
    loop_index += 1
    if(count - (B[argsort[loop_index]]) > 0):
        yen += (A[argsort[loop_index]]*B[argsort[loop_index]])
        count -= B[argsort[loop_index]]
    else:
        yen += A[argsort[loop_index]]*count
        count = 0

print(yen)

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

Solution (Python):
L = []
N, M = map(int, input().split())
for i in range(N):
    A, B = map(int, input().split())
    L.append((A, B))
ans = 0
cnt = 0
for k, v in sorted(L):
    ans += k * v
    cnt += v
    if cnt >= M:
        break
ans -= (cnt - M) * k
print(ans)

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

for j in range(len(AB)):
    if AB[j][1] < M:
        ans += AB[j][0] * AB[j][1]
        M -= AB[j][1]
    else:
        ans += AB[j][0] * M
        break
print(ans)

Solution (Python):
from sys import stdin
from operator import itemgetter

input = stdin.readline

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

AB = [[int(j) for j in input().split()] for i in range(N)]


def main():
    AB.sort(key=itemgetter(0))
    num = 0
    yen = 0
    for i in range(N):
        if M < num + AB[i][1]:
            yen += AB[i][0] * (M - num)
            break
        else:
            yen += AB[i][0] * AB[i][1]
            num += AB[i][1]
    print(yen)
    return


main()

Solution (Python):
n,m=map(int,input().split())
arr=[]
for i in range(n):
	x,y=map(int,input().split())
	arr.append([x,y])
arr=sorted(arr,key=lambda item:item[0])
ans=0
req=m 
for i in range(len(arr)):
	tt=min(arr[i][1],req)
	ans+=(tt*arr[i][0])
	req-=tt
	if req<=0:
		break
print(ans)

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

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)

Solution (Python):
NM = list(map(int, input().split()))
AB = []
for i in range(NM[0]):
    AB.append(tuple(map(int, input().split())))
AB.sort()
M = 0
index=0
ans = 0
while M != NM[1]:
    if M + AB[index][1]>NM[1]:
        ans += (NM[1] - M)* AB[index][0]
        M = NM[1]
    else :
        ans += AB[index][0] * AB[index][1]
        M += AB[index][1]
    index += 1
print(ans)

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

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

i=0
sum_num=0
for j in range(len(data)):
    sum_num=sum_num+data[j][1]
    if M<=sum_num:
        break
    i=i+1
num=sum_num-M
ans=0
for k in range(i):
    ans=data[k][0]*data[k][1]+ans
ans=data[i][0]*(data[i][1]-num)+ans
print(ans)

Solution (Python):
n, m = map(int, input().split())
d = []
num = m
re = 0
for i in range(n):
    tmp = list(map(int, input().split()))
    d.append(tmp)
d = sorted(d)
for i in range(n):
    tmp = d[i]
    b = tmp[1]
    for j in range(b):
        num -= 1
        re += tmp[0]
        if num == 0:
            print(re)
            break
    if num == 0:
        break

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

AB = sorted(AB)

remain_drink = M
price = 0
i = 0
while remain_drink > 0:
    if AB[i][1] <= remain_drink:
        price += AB[i][0] * AB[i][1]
        remain_drink -= AB[i][1]
    else:
        price += AB[i][0] * remain_drink
        remain_drink = 0
    i += 1
print(price)

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

now = m
money = 0
for a,b in sorted_ab:
    if b <= now:
        now -= b
        money += a*b
    else:
        money += a*now
        break
print(money)

Solution (Python):
import sys
n_shops, n_drinks = map(int, input().split())
shop_info = sorted([tuple(map(int, line.split())) for line in sys.stdin.readlines()])
cost = 0
purchased_n_drinks = 0
for _ in range(len(shop_info)):
    info = shop_info.pop(0)
    if (purchased_n_drinks + info[1]) >= n_drinks:
        cost += ( n_drinks - purchased_n_drinks) * info[0]
        break
    purchased_n_drinks += info[1]
    cost += info[0] * info[1]
print(cost)

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

for _ in range(N):
    A, B = list(map(int, input().split()))
    AB_list.append({'A': A, 'B': B})

AB_list.sort(key=lambda t: t['A'])

total_count = 0
total_money = 0
for t in AB_list:
    count = t['B'] if M - total_count > t['B'] else M - total_count
    total_count += count
    total_money += t['A'] * count
    if total_count == 0:
        break

print(total_money)

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

ab.sort()

count=0
num=0
i=0
while count<m:
    if count+ab[i][1]<=m:
        num+=ab[i][0]*ab[i][1]
        count+=ab[i][1]
        i+=1
    else:
        num+=ab[i][0]*(m-count)
        break
print(num)

Solution (Python):
n,m=map(int,input().split())
info=[]
for i in range(n):
    info.append(list(map(int,input().split())))
    
info.sort()

sum_2=0
sum_3=0
index=0
for j in range(n):
    sum_2+=info[j][1]
    if sum_2<m:
        continue
    else:
        index=j
        break
        
for k in range(index):
    sum_3+=info[k][0]*info[k][1]
    
print(sum_3+info[index][0]*(m-(sum_2-info[index][1])))

Solution (Python):
def c():
    N,M= list(map(int,input().split(" ")))
    shops = []
    for i in range(N):
        shop = list(map(int, input().split(" ")))
        shops.append(shop)

    shops.sort(key = lambda x:x[0])
    drinks  = 0
    money = 0
    for shop in shops:
        a = shop[0]
        b = shop[1]
        if drinks + b >=M:
            temp = M - drinks 
            money += temp * a
            break

        else:
            money += b * a
            drinks += b

    print(money)


if __name__ == '__main__':
    c()

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

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

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

money, drink_hon = 0, 0

for a_b in A_B_yasui:
    a, b = a_b[0], a_b[1]
    if drink_hon + b >= M:
        money += (M - drink_hon) * a
        drink_hon += M - drink_hon
        print(money)
        exit()
    else:
        drink_hon += b
        money += b * a

Solution (Python):
n,m = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
a.sort()
money = 0
cnt = 0
i = 0
while cnt < m:
    if cnt + a[i][1] >= m:
        money += (m-cnt)*a[i][0]
        cnt += m-cnt
    else:
        money += a[i][0]*a[i][1]
        cnt += a[i][1]
    i += 1
print(money)

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 = sorted(AB)
cost = 0
tobuy = M
for ab in AB:
    if ab[1] < tobuy:
        cost += ab[0] * ab[1]
        tobuy = tobuy - ab[1]
    else:
        cost += ab[0] * tobuy
        tobuy = 0

    if tobuy == 0:
        break

print(cost)

Solution (Python):
li1 = list(map(int,input().split()))
cnt=0
j=0
drink=[]
for i in range(li1[0]):
    drink.append(list(map(int,input().split())))
drink=sorted(drink,key=lambda x:x[0])
while li1[1]>0:
    if li1[1]>drink[j][1]:
        li1[1]-=drink[j][1]
        cnt+=drink[j][0]*drink[j][1]
    else:
        cnt+=drink[j][0]*li1[1]
        li1[1]=0
    j+=1
print(cnt)

Solution (Python):
import numpy as np

N,M = map(int,input().split())
lst = [ list(map(int,input().split())) for i in range(N)]
lst.sort()

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

print(ans)

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

pon = 0
cost = 0
cnt = 0

while pon < M:
    for i in range(AB[cnt][1]):
        if pon < M:
            cost += AB[cnt][0]
            pon += 1
        else:
            break
    cnt += 1

print(cost)

Solution (Python):
n,m=map(int,input().split())
A=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append([a,b])
A.sort()
katta=0
okane=0
while katta<m:
    
    if A[0][1]+katta<m:
        okane+=A[0][0]*A[0][1]
        katta+=A[0][1]
        A.pop(0)
    else:
        okane+=(m-katta)*A[0][0]
        break
print(okane)

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

shops = []
min_money = 0

for i in range(0, N):
    A, B = map(int, input().split())

    shops.append({'price': A, 'stock': B})

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

for shop in shops:

    
    if M < shop['stock']:
        min_money += shop['price'] * M
        break
    else:
        min_money += shop['price'] * shop['stock']
        M -= shop['stock']

print(min_money)

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

    shop_list = []

    for n in range(N):
        price, quantity = map(int, input().split())
        shop_list.append([price, quantity])

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

    count = 0
    paid = 0
    for price, quantity in shop_list:
        count += quantity
        paid += price*quantity

        if count >= M:
            over_count = count - M
            count -= over_count
            paid -= over_count*price

    print(paid)


if __name__ == "__main__":
    main()