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 = [list(map(int, input().split())) for _ in range(N)]
B = sorted(A, key=lambda x:x[0])
cnt = 0
ans = 0
for i,j in B:
    for k in range(j):
        if cnt == M:
            break
        cnt += 1
        ans += i
else:
    print(ans)

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

pc_list.sort(key=lambda x:(x[0],x[1]))

pc_list

cnt = M
sum_price = 0
for p,c in pc_list:
    
    if c <= cnt:
        sum_price += p*c
        cnt -= c
    else:
        sum_price += p*cnt
        break

print(sum_price)

Solution (Python):
from operator import itemgetter
import numpy as np

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

astores = np.array(sorted(stores, key=itemgetter(0)))

stock = 0
price = 0
for i in range(N):
    if stock + astores[i, 1] > M:
        price += astores[i, 0] * (M - stock)
        break
    else:
        price += astores[i, 0] * astores[i, 1]
        stock += astores[i, 1]

print(price)

Solution (Python):



n, m = map(int, input().split())
h = dict()
for _ in range(n):
    k, v = map(int, input().split())
    if k in h:
        h[k] += v
    else:
        h[k] = v
h = sorted(h.items(), key=lambda x: x[0])


ans = 0
for k, v in h:
    while v > 0:
        if m <= 0:
            print(ans)
            exit()
        else:
            v -= 1
            ans += k
            m -= 1
print(ans)

Solution (Python):



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

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

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

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

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

ans = 0
c = 0
for a, b in AB:
    if c + b < M:
        c += b
        ans += a * b
    else:
        i = M - c
        ans += a * i
        break

print(ans)

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

ab.sort()

count=0
cost=0

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

print(cost)

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

total = 0
for i in drink_list:
    buy = min(m,i[1])
    total += i[0] * buy
    m -= buy

print(total)

Solution (Python):
"""
n = int(sys.stdin.readline())
a, b = map(int, sys.stdin.readline().split())
c = c
s = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  

a = 100
b = 0.987654321
print('{0:06d}-{1:6f}'.format(a,b))  
000100-0.987654


char_list = list("abcd") 
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)


mod = 1000000007

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())
    list_2d = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
    list_2d = sorted(list_2d)
    bought = 0
    total = 0
    for l in list_2d:
        for i in range(l[1]):
            bought += 1
            total += l[0]
            if bought == M:
                print(total)
                exit()

Solution (Python):
import numpy as np

n, m = map(int, input().split())
ab = np.zeros((n, 2))
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    ab[i, 0] = a_tmp
    ab[i, 1] = b_tmp

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

cnt = 0
yen = 0
for i in range(n):
    if m - cnt >= ab[i][1]:
        cnt += ab[i][1]
        yen += ab[i][0] * ab[i][1]
    else:
        yen += (m - cnt) * ab[i][0]
        cnt += m - cnt

        break

print(int(yen))

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

c = zip(a, b)
c=sorted(c)
a, b = zip(*c)
a=list(a)
b=list(b)

d = 0
money = 0
for i in range(n):
    if d == m:
        break
    else:
        if m-d <= b[i]:
            num = m-d
            d += num
            money += num*a[i]
        else:
            num = b[i]
            d += num
            money += num*a[i]

    

print(money)

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

Solution (Python):
n, m = map(int, input().split())
dat_d = []
for i in range(n):
    a,b = map(int, input().split())
    dat_d.append((a, b))
dat_d.sort(key=lambda x: x[0])
total = 0
for i in range(m):
    if dat_d[i][1] >= m:
        
        total += dat_d[i][0] * m
        break
    else:
        
        total += dat_d[i][1] * dat_d[i][0]
        m -= dat_d[i][1]

print(total)

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

a_list = []
b_list = []

for i in range(n):
    a,b = input().split()
    a_list.append(int(a))
    b_list.append(int(b))


price_order = sorted(range(len(a_list)), key=lambda k: a_list[k])

m_carrent = m
sum_price = 0
for p in price_order:
    if m_carrent - b_list[p] >=0:
        sum_price += b_list[p] * a_list[p]
    else:
        sum_price += m_carrent * a_list[p]
        break

    m_carrent -= b_list[p]

print(sum_price)

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

Solution (Python):
N, M = map(int, input().split())
A=[]
total=0
money=0
point=-1
over=0
for i in range(N):
    A.append(list(map(int, input().split())))

A.sort()

while(total<M):
    point +=1
    money+=A[point][0]*A[point][1]
    total +=A[point][1]

over=total-M
money -= over*A[point][0]

print(money)

Solution (Python):




N, M = (int(i) for i in input().split())  
flag = 0
A_list = []
B_list = []
AB_list = []
for i in range(N):
    a,b= (int(j) for j in input().split())  
    A_list.append(a)
    B_list.append(b)
    AB_list.append([a,b])
    pass
AB_list = sorted(AB_list, key=lambda x: x[0])

now = 0
m_cnt = 0
n_cnt = 0
for ab in AB_list:
    
    if n_cnt + ab[1] >= M:
        a = M - n_cnt
        n_cnt += a
        m_cnt += (a * ab[0])
        break
    else:
        n_cnt += ab[1]
        m_cnt += (ab[1] * ab[0])
        pass

print(m_cnt)

Solution (Python):
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
drink = {}
for i in range(0, N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if not a in drink:
        drink[a] = 0
    drink[a] += b

cost = 0
buy_drinks = 0
for price, num in sorted(drink.items()):
    if buy_drinks + num > M:
        cost += (M-buy_drinks) * price
        buy_drinks = M
        break
    else:
        cost += price * num
        buy_drinks += num

print(cost)

Solution (Python):
N, M = map(int, input().split())
lst = []
for i in range(N):
	a, b = map(int, input().split())
	lst.append([a, b])
	
lst = sorted(lst, key = lambda x : x[0])
money = 0
bottle = 0
flg = 0
for elm in lst:
	if flg == 1:
		break
	if bottle + elm[1] < M:
		money += elm[0] * elm[1]
		bottle += elm[1]
	else:
		for i in range(elm[1]):
			money += elm[0]
			bottle += 1
			if bottle >= M:
				flg = 1
				break
print(money)

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

sl = sorted(l)
buy = 0
ans = 0
for i in range(N):
    for j in range(sl[i][1]):
        if buy < M:
            ans += sl[i][0]
            buy += 1
        else:
            break

print(ans)

Solution (Python):
N,M = map(int,input().split())
shop = []
for _ in range(N):
  A = list(int(i) for i in input().split())
  shop.append(A)
shoplist = sorted(shop)
t = 0
k = 0
while k < M:
  k += shoplist[t][1]
  t += 1
x = 0
for i in range(t):
  x += shoplist[i][0]*shoplist[i][1]
print(x-(k-M)*shoplist[t-1][0])

Solution (Python):
import heapq

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

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

cnt = 0
ans = 0
while True:
    a, b = heapq.heappop(shops)
    if cnt + b >= m:
        ans += a * (m - cnt)
        cnt += m - cnt
        break
    else:
        ans += a * b
        cnt += b

print(ans)

Solution (Python):
N,M = map(int,input().split())
a = []
for i in range(N):
    array = list(map(int,input().split()))
    a.append(array)
a.sort()
ans = 0
bought = 0
for i in range(N):
    if bought+a[i][1]>M:
        ans+= a[i][0]*(M-bought)
        bought=M
        print(ans)
        exit()
    ans += a[i][0]*a[i][1]
    bought += a[i][1]
print(ans)

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

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

Solution (Python):
import numpy as np

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

AB.sort()

cnt = 0
yen = 0

for a,b in AB:
  if cnt + b <= M:
    cnt += b
    yen += a * b
    continue
  yen += a * (M - cnt)
  break

answer = yen
print(answer)

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

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

for i in range(N):
    buy = min(M, shop[i][1])
    ans += buy * shop[i][0]
    M -= buy
    if M == 0:
        print(ans)
        exit()

Solution (Python):
n,m=map(int,input().split())
edr=[]
for i in range(n):
  edr.append(list(map(int,input().split())))
edr.sort(key =lambda x:x[0])
cnt=0
ans=0
for i in range(n):
  cnt+=edr[i][1]
  ans+=edr[i][0]*edr[i][1]
  if cnt>=m:
    ans-=(cnt-m)*edr[i][0]
    break
print(ans)

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

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

li = sorted(li,key = lambda x : x[0])
drink = 0
ans = 0
for i in range(n):
  if drink + li[i][1] < m:
    ans += li[i][0]*li[i][1]
    drink += li[i][1]
  else:
    ans += li[i][0]*(m - drink)
    print(ans)
    exit()

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

shop_list = [0] * N

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

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

need_count = M
cost = 0
for item in sorted_list:
    if need_count >= item[1]:
        cost += item[1] * item[0]
        need_count -= item[1]
        if need_count < 0:
            break
    elif need_count < item[1]:
        cost += need_count * item[0]
        need_count -= item[1]
        if need_count < 0:
            break
print(cost)

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

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

total=0
ans=0
for price,num in drinks:
    if total+num<M:
        total+=num
        ans+=price*num
    else:
        ans+=price*(M-total)
        break

print(ans)

Solution (Python):
n, m = map(int,input().split())
l = [[0]*2 for i in range(n)]
for i in range(n):
    l[i][0], l[i][1] = map(int, input().split())
l = sorted(l)
price = 0

for i in range(n):
    if l[i][1] < m:
        m = m - l[i][1]
        price = price + l[i][0]*l[i][1]
    else:
        price = price + l[i][0]*m
        break

print(price)

Solution (Python):
N,m=map(int,input().split())
L=sorted([list(map(int,input().split())) for _ in range(N)])
ans=0
for i in range(N):
	ans+=L[i][0]*min(m,L[i][1])
	m-=min(m,L[i][1])
print(ans)

Solution (Python):
n,m=map(int,input().split())
a=[]
for i in range(0,n):
    b,c=map(int,input().split())
    a.append([b,c])
a.sort()
number=0
for i in range(0,len(a)):
    if number<m:
        number=number+a[i][1]
        l=i
answer=0
kosu=0
for k in range(0,l):
    answer=answer+a[k][0]*a[k][1]
    kosu=kosu+a[k][1]
answer=answer+a[l][0]*(m-kosu)
print(answer)

Solution (Python):
N,M = map(int,input().split())
AB = [[int(_) for _ in input().split()] for i in range(N)]
AB.sort(key = lambda x:x[0])
cost = 0
got = 0
index = 0
s = 0
while got < M:
    got += AB[index][1]
    index += 1
g = got - AB[index-1][1]

plus = M - g

for i in range(index-1):
    cost += AB[i][0] * AB[i][1]
    

cost += plus * AB[index-1][0]    
    
print(cost)

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

n3 = []

for i1 in range(n1):
    n3.append([int(j) for j in input().split()])

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

r1 = 0
for i2 in range(n1):
    if n2 > n3[i2][1]:
        r1 += n3[i2][0] * n3[i2][1]
        n2 -= n3[i2][1]
    else:
        r1 += n3[i2][0] * n2
        break

print(r1)

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

X = []
cost = []
stock = []

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

X.sort()
price, stock = zip(*X)

accumulated = []
accumulated.append(0)

for i in range(n):
  accumulated.append(accumulated[i] + stock[i])

bought = 0
cost = 0
i = 0

while bought + stock[i] < m:
  bought += stock[i]
  cost += price[i] * stock[i]
  i += 1

print(cost + (m - accumulated[i]) * price[i])

Solution (Python):
from operator import itemgetter
N,M=map(int,input().split())
AB=[]
for i in range(N):
    ABtmp=list(map(int,input().split()))
    AB.append(ABtmp)
    
AB.sort(reverse=False,key=itemgetter(0))

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

print(ans)

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


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

list = sorted(list)

quantity = 0
ans = 0

while quantity < m:
    value = list.pop(0)
    ans,quantity = ans+(value[0]*value[1]),quantity+value[1]

if quantity > m:
    temp = quantity-m
    ans = ans-temp*value[0]

print(ans)

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

for a,b in AB:
    if M >= b:
        money += a*b
        M -= b
    else:
        money += a*M
        break
print(money)

Solution (Python):
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(tuple(map(int,input().split())))
a.sort()
count=0
for i in range(n):
  m-=a[i][1]
  count+=a[i][0]*a[i][1]
  if m<=0:
    count+=a[i][0]*m
    print(count)
    break

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

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

ab.sort()

i=0
ans = 0
while m>0:
    if ab[i][1]>m:
        ans += m*ab[i][0]
        break
    else:
        ans += ab[i][1]*ab[i][0]
        m-=ab[i][1]
        i+=1

print(ans)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,m = get_nums_l()
lines = sys.stdin.readlines()

shops = [None] * n
for i,line in enumerate(lines):
    shops[i] = tuple(map(int, line.split(" ")))

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

ans = 0
i = 0
count = 0
while count < m:
    nokori = max(0, m - count)
    kau = min(nokori, shops[i][1])
    count += kau
    ans += kau * shops[i][0]
    i += 1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
ab = []
ans = 0
for i in range(n):
    _a,_b = map(int,input().split())
    ab.append([_a,_b])
sab = sorted(ab)
for i in range(n):
    num = sab[i][1]
    if num <= m:
        m -= num
        ans += sab[i][0]*sab[i][1]
    else:
        ans += sab[i][0]*m
        m = 0
print(ans)

Solution (Python):
from functools import reduce

N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N)))


ans, _ = reduce(
    lambda acc, t:
        (
            acc[0] + t[0] * min(t[1], M - acc[1]),
            acc[1] + t[1]
        ) if acc[1] < M else
        acc,
    sorted(zip(A, B)),
    (0, 0)
)


print(ans)

Solution (Python):
from sys import stdin, stderr, setrecursionlimit, exit
setrecursionlimit(2147483647)
def getint():
    return int(stdin.readline().rstrip('\r\n'))
def getints():
    return [int(i) for i in stdin.readline().rstrip('\r\n').split()]
def getintlines():
    return [int(i) for i in stdin.readlines()]
def getintslines():
    return [[int(i) for i in s.split()] for s in stdin.readlines()]
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n, m = getints()
shops = getintslines()

shops.sort(key=lambda x:x[0])
current_drink = 0
current_money = 0
for price, num in shops:
    current_money += price * num if current_drink + num <= m else price * (m - current_drink)
    current_drink += num
    if current_drink >= m:
        break
    
print(current_money)

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

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

m = 0
c = 0
for a,b in sorted(xs,key=lambda x:x[0]):
    if m+b <= M:
        m+=b
        c+=a*b
    else:
        
        c+=a*(M-m)
        m+=M-m
        break
print(c)

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

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

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

bottle = 0
cost = 0

for n in range(N):
    if AB[n][1] + bottle < M:
        bottle += AB[n][1]
        cost += AB[n][0] * AB[n][1]
    else:
        cost += AB[n][0] * (M-bottle)
        break

print(cost)

Solution (Python):
n,m=map(int,input().split())
ab=[[int(i)for i in input().split()]for _ in range(n)]
ab.sort()
c=0
x=0
for i in range(n):
  m-=ab[i][1]
  c+=1
  if m<=0:
    x-=m
    break
p=0
for i in range(c):
  p+=ab[i][0]*ab[i][1]
print(p-ab[c-1][0]*x)

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

total_amount = 0
total_price = 0
for price,amount in ab:
    bought = min(amount,M-total_amount)
    total_amount += bought
    total_price += price * bought

print(total_price)

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

res = M
total = 0
for i in range(N):
  if(res > AB[i][1]):
    newbuy = AB[i][1]
  else:
    newbuy = res
  total += newbuy*AB[i][0]
  res = res - newbuy

print(total)

Solution (Python):
N,M = map(int,input().split())
ab = []
for n in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
coin = 0
cnt = 0
for n in range(N):
    cnt += ab[n][1]
    coin += ab[n][1] * ab[n][0]
    if cnt >= M:
        coin -= (cnt - M) * ab[n][0]
        print(coin)
        exit()

Solution (Python):

N,M = input().split()
N = int(N)
M = int(M)
ans = 0

AB = []

for i in range(N):

    A,B = input().split()
    AB.append([int(A),int(B)])

AB.sort()

for i in range(N):

    if (AB[i][1] < M):

        M -= AB[i][1]
        ans += AB[i][0] * AB[i][1]

    else:
        ans += AB[i][0] * M
        break

print (ans)

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

while M>0:
    ans+=AB[n][0]*AB[n][1]
    M-=AB[n][1]
    if M<0:
        ans+=M*AB[n][0]
    n+=1
    
print(ans)

Solution (Python):
N,M = map(int,input().split())
AB = list(list(map(int,input().split()))for i in range(N))
AB.sort()
ans = 0
i = 0
while M > 0:
    A,B = AB[i]
    ans += A*B
    M -= B
    i+=1
ans += M*A
print(ans)

Solution (Python):
N,M = map(int,input().split())
AB = list(list(map(int,input().split()))for i in range(N))
AB.sort()
ans = 0
while M > 0:
    A,B = AB.pop(0)
    ans += A*B
    M -= B
ans += M*A
print(ans)

Solution (Python):
n,m=map(int,input().split())
i=0
x=[]
while i!=n:
    a=list(map(int,input().split()))
    x.append(a)
    i=i+1
x.sort()
m_now=0
n_now=0
while m!=m_now:
    a=x[0]
    del x[0]
    if m>=m_now+a[1]:
        m_now=m_now+a[1]
        n_now=n_now+a[0]*a[1]
    else:
        n_now=n_now+a[0]*(m-m_now)
        m_now=m
print(n_now)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()

  l=[]
  for _ in range(n):
    a,b=LI()
    l.append([a,b])

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

  sm=0
  for x in l:
    if m>x[1]:
      m-=x[1]
      sm+=x[0]*x[1]
    else:
      sm+=x[0]*m
      return sm

print(main())

Solution (Python):
def resolve():
    (N, M) = list(map(int, input().split(" ")))
    ABs = [list(map(int, input().split(" "))) for i in range(N)]
    sortedABs = sorted(ABs, key=lambda x: x[0])
    cost = 0
    num = 0
    for ab in sortedABs:
        if ab[1] < M-num:
            num = num + ab[1]
            cost = cost + ab[0]*ab[1]
        else:
            cost = cost + ab[0]*(M-num)
            break
    print(cost)

if '__main__' == __name__:
    resolve()

Solution (Python):
import heapq
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)


N, M = map(int, input().split())
A, B = [0] * N, [0] * N
C = []

for i in range(N):
	A[i], B[i] = map(int, input().split())
	heapq.heappush(C, (A[i], B[i]))
	
ans = 0

for i in range(M):
	tmp = heapq.heappop(C)
	ans += tmp[0]
	if tmp[1] > 1:
		heapq.heappush(C, (tmp[0], tmp[1] - 1))

print(ans)

Solution (Python):
nm, left = map(int, input().split())
shops = []
for _ in range(nm):
    shops.append([int(x) for x in input().split()])
shops.sort(key=lambda x: x[0])

total_cost = 0
for cost, stock in shops:
    if stock >= left:
        print(total_cost + cost * left)
        exit(0)
    else:
        left = left - stock
        total_cost += cost * stock

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

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

Solution (Python):
def resolve():
	N,M=map(int,input().split())
	L=[]
	for i in range(N):
		a,b=map(int,input().split())
		L.append([a,b])
	D=sorted(L,key=lambda x:x[0])
	ans=0
	cnt=M
	for i in D:
		if i[1]<cnt:
			ans+=i[0]*i[1]
			cnt-=i[1]
		else:
			ans+=i[0]*cnt
			break
	print(ans)
resolve()

Solution (Python):



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)
    
L = list(zip(A,B))
L.sort()







yen = 0

while True:
    i = 0
    
    
    if L[0][1] >= M:
        yen += M*L[0][0]
        break
    else:
        yen += L[0][1] * L[0][0]
        M -= L[0][1]
        del L[0]
        
        
print(yen)

Solution (Python):
num_of_drink = [int(i) for i in input().split()]
shop = [[int(i) for i in input().split()] for j in range(num_of_drink[0])]
buing_scajule = sorted(shop)
cash = 0
must_drink_num = num_of_drink[1]
i = 0

while must_drink_num != 0:
    if buing_scajule[i][1] >= must_drink_num:
        cash += buing_scajule[i][0] * must_drink_num
        must_drink_num = 0
    else:
        cash += buing_scajule[i][0] * buing_scajule[i][1]
        must_drink_num -= buing_scajule[i][1]
    i += 1

print(cash)

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


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

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

res = 0
while m > 0:
  if l[0][1] == 0:
    l.pop(0)
  else:
    res += l[0][0]
    l[0][1] -= 1
    m -= 1
print(res)

Solution (Python):
shops, need_drink = [int(x) for x in input().split()]

price_quantity = []
for count in range(shops):
    data = [int(x) for x in input().split(" ")]
    price_quantity.append(data)



price_quantity.sort(key=lambda x: x[0])
bought_drink = 0
counter2 = 0
total_cost = 0

while bought_drink < need_drink:
    if (price_quantity[counter2][1] + bought_drink) < need_drink:
        bought_drink += price_quantity[counter2][1]
        total_cost += price_quantity[counter2][0] * price_quantity[counter2][1]
    else:
        while price_quantity[counter2][1] != 0:
            price_quantity[counter2][1] -= 1
            bought_drink += 1
            total_cost += price_quantity[counter2][0]
            if bought_drink >= need_drink:
                break
    counter2 += 1

print(total_cost)

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

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

for i in range(N):
  AB.append([int(i) for i in input().split()])

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

count = 0
ans = 0

for A,B in AB:
  if count + B > M:
    ans += A*(M-count)
    break
  else:
    ans += A*B
    count += B


print(ans)

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

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

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

now = 0
ans = 0

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


print(ans)

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

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

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

count = 0
payment = 0
for i in a_b:
  count += i[1]
  payment += i[0] * i[1]
  if count >= m:
    payment -= (count - m) * i[0]
    break

print(payment)

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

Solution (Python):
from sys import stdin
import numpy as np
n, m = (int(i) for i in input().rstrip().split())

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

for itr in range(n):
    a, b = (int(i) for i in input().rstrip().split())
    vals_list[itr][0], vals_list[itr][1] = a, b
sorted_vals_list = vals_list[np.argsort(vals_list[:, 0])]


cnt = m
total_money = 0
for itr in range(n):
    if (cnt - sorted_vals_list[itr][1]) <= 0:
        total_money += sorted_vals_list[itr][0] * cnt
        break
    else:
        cnt -= sorted_vals_list[itr][1]
        total_money += sorted_vals_list[itr][0] * sorted_vals_list[itr][1]
print(int(total_money))

Solution (Python):
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
X.sort(key=lambda x: x[0])
ans = 0
for k in range(N):
    if M == 0:
        break
    buy = min(X[k][1], M)
    M -= buy
    ans += buy * X[k][0]
print(ans)

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

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

ab_list_sorted = sorted(ab_list, reverse=False, key=lambda x:x[0])

nokori_honsu = M
cost = 0

for ab in ab_list_sorted:
    if ab[1] >= nokori_honsu:
        cost += nokori_honsu * ab[0]
        break
    else:
        cost += ab[1] * ab[0]
        nokori_honsu -= ab[1]
        
print(cost)

Solution (Python):

import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
ans = 0
for i in lst:
    while i[1] > 0 and m > 0:
        ans += i[0]
        i[1] -= 1
        m -= 1
print(ans)