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

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


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

buy = 0
sum_money = 0
for i in range(N):
    price = price_amount_list[i][0]
    amount = price_amount_list[i][1]
    if buy + amount < M:
        sum_money += price * amount
        buy += amount
    else:
        sum_money += price * (M-buy)
        buy += (M-buy)
        break

print(sum_money)

Solution (Python):

def main():
	bought = 0
	money = 0
	DrinkList = []
	N,M = map(int,input().split())
	for i in range(N) :
		a,b = map(int,input().split())
		DrinkList.append( (a,b) )
	DrinkList.sort()
	for price,drink_max in DrinkList :
		for i in range(drink_max) :
			if bought < M :
				money += price
				bought += 1
			if bought == M :
				print(money)
				return 0
	
if __name__ == "__main__" :
	main()

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

m = 0
money = 0

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

for store in stores:
    money += min(store[1], M - m) * store[0]
    m += min(store[1], M - m)
    
print(money)

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

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

count = 0
amt = 0
for a_b in A_B:
    a = a_b[0]
    b = a_b[1]
    if count + b < M:
        count += b
        amt += a * b
        continue
    else:
        amt += ((M - count) * a)
        break

print(amt)

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


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

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

m = 0
money = 0

for store in stores:
  money += min(store[1], M - m) * store[0]
  m += min(store[1], M - m)
  if m == M:
    break
print(money)

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

n_drinks = 0
ans = 0

for i in range(n):
    a_yen = ab[i][0]
    b_hon = ab[i][1]

    if (m - n_drinks) >= b_hon:
        n_drinks += b_hon
        ans += a_yen * b_hon
    else:
        n_buy = m - n_drinks
        ans += a_yen * n_buy
        break

print(ans)

Solution (Python):
N, M = map(int, input().split())
stores = []
for i in range(N):
    stores.append(list(map(int, input().split())))
stores.sort()
answer = 0
for store in stores:
    yasui = min(M, store[1])
    M -= yasui
    answer += store[0] * yasui
    if M == 0:
        break
print(answer)

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

A_B.sort()
count = 0
cost = 0 
for abi in A_B:
  if count == M:
    print(cost)
    exit()
  else:
    for i in range(abi[1]):
      count += 1
      cost += abi[0]
      if count == M:
        print(cost)
        exit()

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

y=d=0
for i in ab:
    y+=i[0]*i[1]
    d+=i[1]
    if(d>=M):
        print(y-(d-M)*i[0])
        exit()

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

sorted_ab = sorted(ab)
collected = 0
cost = 0
for i in range(n):
    a, b = sorted_ab[i]
    if b > m - collected:
        cost += (m - collected) * a
        break
    else:
        cost += a * b
        collected += b

print("{:d}".format(cost))

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

AB.sort()

cnt=0
total=0
i = 0
while cnt < M:
	cnt += AB[i][1]
	total += AB[i][0]*AB[i][1]
	i+=1
total -=  AB[i-1][0]*(cnt-M)
print(total)

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

AB = [0]*N
for i in range(N):
    AB[i] = tuple(map(int, input().split()))
AB.sort()

money = 0 
for A, B in AB: 
    if B <= M:
        money += A*B 
    else:
        money += A*M 
        break
    M -= B                                                                                                     

print(money)

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

num_drink=0
price=0
a.sort()
for i in a:

    if num_drink+i[1]<m:
        
        num_drink+=i[1]
        price+=i[1]*i[0]

    else:
        price+=(m-num_drink)*i[0]

        break
    
print(price)

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

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

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

money = 0
count = 0

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

print(money)

Solution (Python):
import numpy as np

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







data.sort()

num_drink=0
cost=0
shop_index=0
while (shop_index < N and num_drink < M):
    num_drink += data[shop_index][1]
    cost += data[shop_index][0]*data[shop_index][1]
    shop_index += 1


excess = num_drink - M
ans = cost - data[shop_index-1][0] * excess
print(ans)

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

    shops.sort()

    total_price = 0
    total_bottles = 0
    for price, bottles in shops:
        if (total_bottles + bottles) < m:
            total_price += price * bottles
            total_bottles += bottles
        else:
            total_price += price * (m - total_bottles)
            break
    print(total_price)


if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np


N,M=map(int,input().split())
AB=np.zeros((N,2))
for i in range(N):
    AB[i,0],AB[i,1]=map(int,input().split())
AB = AB[np.argsort(AB[:, 0])]
numd=0
ans=0
for i in range(len(AB)):
    if numd==M:
        break
    else:
        if AB[i][1] < M-numd:
            ans+=AB[i][0]*AB[i][1]
            numd+=AB[i][1]
        else:
            ans+=AB[i][0]*(M-numd)
            numd+=M-numd
print(int(ans))

Solution (Python):
N,M=map(int,input().split())
a=[list(map(int,input().split()))for i in range(N)]
money=0
a.sort()
flag=False
s=0
for i in range(N):
    if flag:
        break
    s+=a[i][1]
    count=a[i][1]
    if s>M:
        count-=s-M
        flag=True
    money+=count*a[i][0]
print(money)

Solution (Python):
N, M = map(int, input().split())
lis = []
for _ in range(N):
  a, b = map(int, input().split())
  lis.append((a, b))
def eval(data):
  return data[0]
lis.sort(key=eval)
total = 0
num = 0
mark = 0
for i in range(N):
  num = num + lis[i][1]
  total = total + lis[i][0]*lis[i][1]
  if num > M:
    mark = i
    total = total - lis[i][0]*lis[i][1]
    num = num - lis[i][1]
    break
total = total + (M - num)*lis[mark][0]
print(total)

Solution (Python):


import bisect

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

Aacc, Bacc = [0], [0]
for i in range(N):
    Aacc.append(Aacc[-1] + AB[i][0] * AB[i][1])
    Bacc.append(Bacc[-1] + AB[i][1])

idx = bisect.bisect(Bacc, M)
print(Aacc[idx - 1] if Bacc[idx - 1] == M else Aacc[idx - 1] + AB[idx - 1][0] * (M - Bacc[idx - 1]))

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

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

c = sorted(zip(a,b))
ans = 0
for (s, t) in c:
    if m >= t:
        ans += s * t
        m -= t
    else:
        ans += s * m
        break

print(ans)

Solution (Python):
import sys
from operator import itemgetter


def parse_input(input_lines):
    return tuple(map(lambda sl: tuple(map(int, sl)),
                     map(lambda s: s.strip().split(),
                         input_lines)))


def main(inps):
    (N, M), *shops = inps
    shops = sorted(shops, key=itemgetter(0))
    result = 0
    for cost, count in shops:
        if M > count:
            result += cost * count
            M -= count
        else:
            result += cost * M
            return result


if __name__ == '__main__':
    inps = parse_input(sys.stdin.readlines())
    print(main(inps))

Solution (Python):


data = input().split()
shoplist = []
for i in range(int(data[0])):
    shopdata = list(map(int, input().split()))
    shoplist.append(shopdata)
shoplist.sort()

payment = 0
wantdrink = int(data[1])
while wantdrink > 0 :
    restdrink = shoplist[0][1]
    if restdrink >= wantdrink:
        payment += wantdrink * shoplist[0][0]
        break
    else:
        payment += restdrink * shoplist[0][0]
        wantdrink -= restdrink
        del shoplist[0]
print(payment)

Solution (Python):
total_cost = 0

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

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

AB_list = sorted(AB_list)

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

Solution (Python):
n,m = map(int,input().split(" "))
ar = []
for i in range(n):
    l = list(map(int,input().split(" ")))
    ar.append(l)
ar.sort()
mo = 0
count = 0
i = 0
while True:
    if count + ar[i][1] > m:
        mo += ar[i][0] * (m - count)
        break
    else:
        mo += ar[i][0] * ar[i][1]
        count += ar[i][1]
    if count == m:
        break
    i += 1
print(mo)

Solution (Python):
n,m=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
drink=0
price=0
i=0
l.sort(key=lambda x: x[0])
while drink<m:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    drink+=num
    price+=pri*num
if drink>m:
    price-=(drink-m)*pri
print(price)

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

    
x.sort()
result=0
while 1:
    if x[0][1]>=m:
        result+=m*x[0][0]
        break
    else:
        result+=x[0][0]*x[0][1]
        m-=x[0][1]
        del x[0]
print(result)

Solution (Python):
n,m = list(map(int,input().split()))
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
x.sort()
result=0
while 1:
    if x[0][1]>=m:
        result+=m*x[0][0]
        break
    else:
        result+=x[0][0]*x[0][1]
        m-=x[0][1]
        del x[0]
print(result)

Solution (Python):
from sys import stdin

n, m = [int(x) for x in stdin.readline().rstrip().split()]
data = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(n)]

data = sorted(data)
ans = 0
current = 0
i = 0
while True:
    if m > current + data[i][1]:
        ans += data[i][0] * data[i][1]
        current += data[i][1]
        i += 1
    else:
        ans += data[i][0] * (m - current)
        print(ans)
        exit()

Solution (Python):
import sys

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

a = []

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

a.sort()

i = 0
ans = 0

while m > 0:
    if m > a[i][1]:
        ans += a[i][0] * a[i][1]
        m = m - a[i][1]
        i += 1
    else:
        ans += a[i][0] * m
        print(ans)
        sys.exit()

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

mat = list(list(map(int, input().split())) for i in range(N))
mat = sorted(mat, key=lambda x: x[0])

i = 0
cost = 0
num = 0
while num<M:
    if M-num >= mat[i][1]:
        num += mat[i][1]
        cost += mat[i][1] * mat[i][0]
        i += 1
    else:
        cost += mat[i][0] * (M-num)
        num += M-num
print(cost)

Solution (Python):


from sys import stdin

input = stdin.readline

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

AB.sort()

amount = 0
charge = 0

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

print(charge)

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

li_sorted = sorted(li)
num_bought = 0
answer = 0
j=0
while(num_bought<M):
    if li_sorted[j][1]>M-num_bought:
        answer += li_sorted[j][0]*(M-num_bought)
    else:
        answer += li_sorted[j][0]*li_sorted[j][1]
    num_bought += li_sorted[j][1]
    j += 1
    
print(answer)

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

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

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

ans = 0
for a, b in stores:
  buy = min(b, m)
  m -= buy
  ans += a * buy
  if m == 0:
    break
print(ans)

Solution (Python):
import re
import numpy as np

np.seterr(over='raise')

N, M = [int(item) for item in re.split(r"\s", input())]

AB = []
for _ in range(N):
    AB.append([int(item) for item in re.split(r"\s", input())])

AB = np.array(AB)
A = AB[:, 0]
B = AB[:, 1]


sorted_B = B[np.argsort(A)]
sorted_A = np.sort(A)


cumB = np.cumsum(sorted_B)
index = np.argmax(cumB > M)

if N > 1 and index > 0:
    total = np.sum(sorted_A[:index] * sorted_B[:index])
    total = total + (M - cumB[index - 1]) * sorted_A[index]
else:
    total = M * sorted_A[0]

print(total)

Solution (Python):
mn,dn=map(int,input().split(" "))
ne_zai=[]
for _ in range(mn):
    ne_zai.append(list(map(int,input().split(" "))))
ne_zai.sort()
kin=0
for i in range(mn):
    if ne_zai[i][1]<dn:
        kin+=ne_zai[i][0]*ne_zai[i][1]
        dn-=ne_zai[i][1]
    else:
        kin+=dn*ne_zai[i][0]
        break
print(kin)

Solution (Python):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
bottle, cost, i = 0, 0, 0
while bottle < M:
    cost += AB[i][0] * AB[i][1]
    bottle += AB[i][1]
    i += 1

cost -= (bottle - M) * AB[i-1][0]
print(cost)

Solution (Python):
def main():
    N, M = map(int, input().split())
    AB = sorted([tuple(map(int, input().split()))
                 for _ in range(N)], key=lambda x: x[0])
    ans = 0
    for A, B in AB:
        ans += min(M, B) * A
        M -= B
        if 0 >= M:
            break
    print(ans)


main()

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

A=[0]*N
B=[0]*N

for i in range(0,N):
  tmp=list(map(int,input().split()))
  A[i]=tmp[0]
  B[i]=tmp[1]
c=zip(A,B)
c=sorted(c)
total=0
idx=0
totalcan=0
while totalcan<M:
  total+=c[idx][0]*c[idx][1]
  totalcan+=c[idx][1]
  idx+=1

while totalcan>M:
  total-=c[idx-1][0]
  totalcan-=1
print(str(total))

Solution (Python):

import sys

amount = 0


[n, m] = map(lambda x: long(x), sys.stdin.readline().split(" "))
for row in sorted([sys.stdin.readline() for _ in range(n)], key=lambda x: long(x.split(" ")[0])):
    [ai, bi] = map(lambda x: long(x), row.strip().split(" "))
    x = bi if m >= bi else m
    amount += ai * x
    m -= x
    if m == 0:
        break

print amount

Solution (Python):

import sys

head = sys.stdin.readline()
[n, m] = map(lambda x: long(x), head.split(" "))

amount = 0


rows = [sys.stdin.readline() for _ in range(n)]
rows.sort(key=lambda x: long(x.split(" ")[0]))
for row in rows:
    [ai, bi] = map(lambda x: long(x), row.strip().split(" "))
    
    x = bi if m >= bi else m
    amount += ai * x
    m -= x
    if m == 0:
        break

print amount

Solution (Python):

import sys

head = sys.stdin.readline()
[n, m] = head.split(" ")
n = long(n)  
m = long(m)  

amount = 0


rows = [sys.stdin.readline() for _ in range(n)]
rows.sort(key=lambda x: long(x.split(" ")[0]))
for row in rows:
    [a, b] = row.strip().split(" ")
    ai = long(a) 
    bi = long(b) 
    
    x = bi if m >= bi else m
    for var in range(x):
        amount += ai
    m -= x
    if m == 0:
        break

print amount

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

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):
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):
import sys
input=sys.stdin.readline
N,M=[int(_) for _ in input().split()]
iCost = 0
for a, b in sorted([int(_) for _ in input().split()] for _ in range(N)):
    if b < M:
        iCost += a*b
        M -= b
    else:
        iCost += a*M
        print(iCost)
        exit()

Solution (Python):
n,m=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
have=0
yen=0
i=0
l.sort(key=lambda x: x[0])
while have<m:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)

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


AB = sorted(AB, key=lambda x: x[0])
ans = 0
cans = 0
for i in range(N):
    if cans + AB[i][1] >= M:
        ans += AB[i][0] * (M-cans)
        print(ans)
        quit()
    else:
        cans += AB[i][1]
        ans += AB[i][0] * AB[i][1]

Solution (Python):


n,m=map(int,raw_input().split())
l=[]
for i in xrange(n):
 l.append(map(int,raw_input().split()))
l.sort()
b=0
s=0
for i in xrange(n):
 b+=l[i][1]
 s+=l[i][0]*l[i][1]
 if b>m:
  s-=l[i][0]*l[i][1]
  s+=l[i][0]*(l[i][1]-b+m)
  break
print s

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

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)

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

for _ in range(N):
  lst.append([int(x) for x in input().split()])

lst.sort()

cost = 0
i = 0

while i < len(lst):
  l = lst[i]
  if l[1] < M:
    M -= l[1]
    cost += l[0] * l[1]
    i += 1
    continue
  else:
    cost += l[0] * M
    break

print(cost)

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

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

cnt = 0
price = 0
i = 0
while cnt < m:
    price += ab[i][0] * ab[i][1]
    cnt += ab[i][1]
    if cnt > m:
        price -= ab[i][0] * (cnt - m)
        break
    i += 1

print(price)

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

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

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

cost = 0
remain = M
for a in Ai:
    if remain == 0:
        break
    buy_num = min(a[1], remain)
    cost += a[0] * buy_num
    remain -= buy_num
print(cost)

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

Solution (Python):
N, M = [int(i) for i in input().split()]
cost = 0
amount =0
dic ={}
for _ in range(N):
    a,b = [int(i) for i in input().split()]
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b

dic = sorted(dic.items())

for a,b in dic:
    if amount+b<=M:
        amount += b
        cost += a*b
    else:
        rest = M - amount
        cost += a*rest
        break

print(cost)

Solution (Python):
N, M = [int(i) for i in input().split()]
ary = [[int(i) for i in input().split()] for j in range(N)]
na = sorted(ary)
sum = 0
remain = M
for i in na:
    if remain >= i[1]:
        sum += i[1]*i[0]
        remain -= i[1]
    else:
        sum += remain * i[0]
        remain = 0
print(sum)

Solution (Python):
import numpy as np
N,M=map(int,input().split())
A=[]
 
for i in range(N):
    A+=[[i for i in map(int,input().split())]]
A=np.array(A)
A=A[A[:,0].argsort(),:]

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

print(price)

Solution (Python):

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

list = [list(map(int, input().strip().split())) for i in range(N)]	
list.sort(key = lambda x : x[0])
sum = 0
cnt = 0
for a, b in list:
	if cnt + b < M:
		sum += a*b
		cnt += b
	else:
		sum += a*(M - cnt)
		break

print(sum)

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

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

list.sort()
sum = 0
cnt = 0

for A,B in list:
    if cnt + B >= M:
        sum += A*(M - cnt)
        cnt += M - cnt
        break
    sum += A*B
    cnt += B

print(sum)

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

drinks = 0
cost = 0
for store in stores:
    if drinks + store[1] <= m:
        drinks += store[1]
        cost += store[0]*store[1]
    elif drinks + store[1] > m:
        cost += (m - drinks)*store[0]
        break
print(cost)

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

drinks = 0
cost = 0
for store in stores:
    if drinks + store[1] <= m:
        drinks += store[1]
        cost += store[0]*store[1]
    elif drinks + store[1] > m:
        cost += (m - drinks)*store[0]
        break
print(cost)

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

d=0
ans =0
for a,b in ab:
  if d+b <= M:
    ans += a*b
    d += b
  else:
    ans += (M-d)*a
    break
print(ans)

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

    for ab in AB:
        a = ab[0]
        for b in range(ab[1]):
            count += a
            M -= 1
            if M == 0:
                print(count)
                return 0

main()

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

sum = 0
remain_cnt = M
i = 0

while(True):
    if remain_cnt <= AB[i][1]:
        sum += remain_cnt * AB[i][0]
        break

    sum += AB[i][0] * AB[i][1]
    remain_cnt -= AB[i][1]
    i += 1

print(sum)

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

ans=0
for a,b in Shop:
    if b < M:
        ans += (a*b)
        M-=b
    else:
        ans += (M*a)
        break

print(ans)

Solution (Python):
import sys


fin = sys.stdin.readline
N, M = [int(elem) for elem in fin().split()]
drinks = sorted([tuple(int(elem) for elem in fin().split()) for _ in range(N)], \
    key=lambda drink: (drink[0], -drink[1]))
assert len(drinks[0]) == 2

necessary_money = 0
num_bought_bottles = 0

for price, num_bottles in drinks:
    if num_bought_bottles + num_bottles < M:
        necessary_money += price * num_bottles
        num_bought_bottles += num_bottles
    else:
        necessary_money += price * (M - num_bought_bottles)
        break
print(necessary_money)

Solution (Python):
n,m = map(int,input().split())
ab = []
for i in range(n):
        ab.append([int(j) for j in input().split()])
ab.sort()
cnt = 0
ans = 0
for i in ab:
    cnt += i[1]
    ans += i[0]*i[1]
    if cnt >= m:
        ans -= i[0]*(cnt-m)
        print(ans)
        exit()

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

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

A, B = zip(*sorted(zip(A, B)))

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

print(cost)

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

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

AB.sort()

cost = 0
total_n = 0
i = 0



while True:
    if total_n + AB[i][1] >= M:
        break
    cost += (AB[i][0] * AB[i][1])
    total_n += AB[i][1]
    
    i += 1

cost += (M - total_n) * AB[i][0]

print(cost)

Solution (Python):
n,m = map(int,input().split())
stores = list()
cost = 0

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

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

for store in stores:
    if store[1] <= m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        m -= store[1]
        if m <= 0:
            break

print(cost)

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

X.sort()
ans = 0
k = M
for a, b in X:
     x = min(k, b)
     ans += a * x
     k -= x
     if k == 0:
         break
print(ans)

Solution (Python):
T=list(map(int,input().split()))
N = T[0]
M = T[1]
A = []
B = []
count = 0
num = 0
for i in range(N):
	P=list(map(int,input().split()))
	A.insert(i,P[0])
	B.insert(i,P[1])

d=zip(A,B)
d1 = sorted(d)

for a,b in d1:
	for j in range(b):
		if(count == M):
			break
		count = count + 1
		num = num + a
	else:
		continue
	break
print(num)

Solution (Python):
import numpy as np

N, M = map(int, input().split())
ab = np.zeros((N, 2))
for i in range(N):
    ab[i,:] = list(map(int, input().split()))
ab = ab[ab[:,0].argsort(), :]

cost = 0
for i in range(N):
    M -= ab[i,1]
    cost += ab[i,0] * ab[i,1]
    if M <= 0:
        cost += ab[i,0] * M
        break

print(int(cost))

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


X.sort(key=lambda x: x[0])
i = 0
total = 0
ans = 0

while i <= N-1:
	total += X[i][1]
	ans += X[i][0] * X[i][1]
	if total > M:
		ans -= X[i][0] * (total-M)
		break
	i += 1
print(ans)

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

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

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

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

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

honsuu = 0
price = 0
for i in arr:
	temp = min(i[1], m-honsuu)
	honsuu += temp
	price += i[0] * temp

print(price)

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


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

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

print(cost)

Solution (Python):
def main(ab_list, m):
    ab_list.sort(key=lambda x:x[0])
    it = iter(ab_list)
    paid = 0
    buyed_drinks = 0
    while buyed_drinks < m:
        rest_num = m - buyed_drinks
        a, b = next(it)
        if rest_num <= b:
            paid += a*rest_num
            return paid
        else:
            paid += a*b
            buyed_drinks += b



if __name__ == "__main__":
    n, m = list(map(int, input().split(" ")))
    ab_list = []
    for _ in range(n):
        a, b = list(map(int, input().split(" ")))
        ab_list.append((a, b))
    print(main(ab_list, m))

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

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

a = sorted(a)

i = 0
num = 0
ans = 0
while i <= N - 1:
  ans += a[i][0] * a[i][1]
  num += a[i][1]
  if num > M:
    ans -= a[i][0] * (num - M)
    break
  i += 1
print(ans)

Solution (Python):
from operator import itemgetter

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


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

if N ==1:
    Z = M*a[0][0]
    print(Z)
else:
    a.sort(key = itemgetter(0))
    X = 0 
    D = 0
    var=0
    while M>D:
        D+=a[var][1]
        X+=a[var][0]*a[var][1]
        var+=1
        
    X += a[var-1][0]*(M-D)
    print(X)

Solution (Python):
N, M, *L = map(int, open(0).read().split())
ans = 0
for i, j in sorted(zip(L[::2], L[1::2])):
    ans += i * min(M, j)
    M -= j
    if M <= 0:
        print(ans)
        break