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

Solution (Python):


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


nokori = M
ab_list = sorted(ab_list, key= lambda x: x[0])
ans = 0


i = 0
while nokori>0:
    ab = ab_list[i]
    a = ab[0]
    b = ab[1]
    if b<=nokori:
        ans += a * b
        nokori -= b
    else:
        ans += a * nokori
        break
    i += 1


print(ans)

Solution (Python):
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

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

tmp = [None]*n
for i in range(n):
    tmp[i] = [None]*2
for i in range(n):
    tmp[i] = readints()

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

cnt = 0
cost = 0
for i in range(n):
    if tmp_so[i][1] <= m:
        m -= tmp_so[i][1]

        cost += tmp_so[i][1]*tmp_so[i][0]
    elif m <= tmp_so[i][1]:

        cost += m*tmp_so[i][0]
        m = 0
print(cost)

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])
ans=0
for a,b in ab:
  if m>=b:
    m-=b
    ans+=b*a
  else:
    ans+=a*m
    break
print(ans)

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort(key=lambda x:x[0])

j=0
ans=0
i=0
while j<n and i<m:
    
    if lis[j][1]>0:
        lis[j][1]-=1
        ans+=lis[j][0]
        i+=1
    else:
        j+=1
print(ans)

Solution (Python):
import sys

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

AB.sort()

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

Solution (Python):
N, M, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)
A.sort()

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

Solution (Python):
N,M = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
cnt = 0
cost = 0
for i in range(N):
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:
        d = M-cnt
        cost += a*d
        break
print(cost)

Solution (Python):
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
money = 0
drink = 0
for a,b in ab:
    if drink+b <= m:
        drink += b
        money += a*b
    else:
        money += (m-drink) * a
        drink = m
    if drink == m: break
print(money)

Solution (Python):
n,m=map(int,input().split())
costs=[]
for i in range(n):
  a,b=map(int,input().split())
  costs.append([a,b])
costs=sorted(costs, key=lambda student: student[0])
pointer=0
ans=0
while m>0:
  costs[pointer][1]-=1
  ans+=costs[pointer][0]
  m-=1
  if costs[pointer][1]==0:
    pointer+=1
print(ans)

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

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

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

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 a, b in AB:
    if b <= m:
        ans += a*b
        m -= b
    else:
        ans += a*m
        m = 0
    if m == 0:
        break
print(ans)

Solution (Python):

import collections
n,m = map(int,raw_input().split(' '))

costs = [map(int, raw_input().split(' ')) for _ in range(n)]
costs.sort(key = lambda x:-x[0])
q = collections.deque(costs)
r = 0
while(m):
	u,v = q.pop()
	t = min(v,m)
	m -=t
	r += t * u
print r

Solution (Python):
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
ans = 0
i = 0
ab.sort()
while cnt < M:
    tmp = ab[i][1]
    prc = ab[i][0]
    ans += prc * tmp
    cnt += tmp
    i += 1
print(ans - (cnt-M)*prc)

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

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

    ABs = sorted(ABs)
    Count = 0
    ans = 0
    for i in range(n):
        if Count == m:
            break
        if ABs[i][1] + Count <= m:
            ans += ABs[i][0] * ABs[i][1]
            Count += ABs[i][1]
        else:
            o = m - Count
            ans += ABs[i][0] * o
            Count += o

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n,m=map(int,input().split())
    s=[tuple(map(int,input().split())) for _ in range(n)]
    s.sort(key=lambda x: x[0])
    bought = 0
    cost = 0
    for yen, ko in s:
        cost += ko*yen
        bought += ko
        
        if bought >= m:
            cost -= (bought-m)*yen
            break
    print(cost)
    
if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, input().split())
d = [tuple(map(int, input().split())) for _ in range(n)]
d.sort()
ans = 0
for ai, bi in d:
    if m <= bi:
        ans += ai * m
        break
    ans += ai * bi
    m -= bi
print(ans)

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

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

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

input_n = lambda: int(readline())
input_nn = lambda: map(int, readline().split())
input_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, M = input_nn()
    AB = sorted([list(input_nn()) for _ in range(N)])

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

n, m = map(int, input().split())
v = []
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    v += [(a, b)]
v.sort(key=lambda x: x[0])
for i in v:
    m -= i[1]
    if m >= 0:
        ans += i[0]*i[1]
    else:
        m += i[1]
        ans += m*i[0]
        break
print(ans)

Solution (Python):
from collections import defaultdict
n,m=map(int,input().split())

price_list=[0]*n
num_dic=defaultdict(int)

def mergesort(a):
    def _merge_sort(a, left: int, right: int):
        if left < right:
            center = (left+right)//2

            _merge_sort(a,left,center)
            _merge_sort(a,center+1,right)

            
            p=j=0
            i=k=left

            
            while i <= center:
                buff[p]=a[i]
                p+=1
                i+=1

            
            while i<= right and j < p:
                if buff[j] <= a[i]:
                    a[k]=buff[j]
                    j+=1
                else:
                    a[k]=a[i]
                    i+=1
                k+=1

            while j < p:
                a[k] =buff[j]
                k+=1
                j+=1

    n=len(a)
    
    buff=[None]*n
    _merge_sort(a,0,n-1)
    del buff

for i in range(n):
    a,b=map(int,input().split())
    price_list[i]=a
    if num_dic[price_list[i]] is None:
        num_dic[price_list[i]]=b
    else:
        num_dic[price_list[i]]+=b

mergesort(price_list)

price_sum=0
drink_count=0
for i in range(n):
    if i!=0 and price_list[i-1]==price_list[i]:
        continue
    else:
        
        drink_count+=num_dic[price_list[i]]
        if drink_count>m:
            drink_count-=num_dic[price_list[i]]
            stop=i
            break
        p=price_list[i]*num_dic[price_list[i]]
        price_sum+=p

k=m-drink_count
price_sum+=price_list[i]*k

print(price_sum)

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

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


pay=0
i=0
while m>0:
    p=min(m,a[i][1])
    m-=p
    pay+=p*a[i][0]
    i+=1
print(pay)

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

    shops = []
    for i in range(N):
        aa, bb = map(int, input().split())
        shops.append([aa, bb])

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

    rem = M
    ans = 0
    for shop in shops:
        buy = min(rem, shop[1])
        ans += buy * shop[0]
        rem -= buy

    print(ans)


resolve()

Solution (Python):
N, M, *AB = map(int, open(0).read().split())
AB = list(zip(*[iter(AB)]*2))

num = 0
cost = 0

for a, b in sorted(AB):
    if num+b >= M:
        cost += (M-num)*a
        break
    else:
        num += b
        cost += b*a

print(cost)

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

count = 0
money = 0
for list in arr:
    for i in range(list[1]):
        money += list[0]
        count += 1
        if count == M:
            print(money)
            exit()

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

cost = 0
for i in range(n):
  if m <= AB[i][1]:
    cost += m * AB[i][0]
    print(cost)
    exit()
  else:
    m = m - AB[i][1]
    cost += AB[i][1] * AB[i][0]
    
print(cost)

Solution (Python):
n,m,*l=map(int,open(0).read().split());c=0
for a,b in sorted(zip(*[iter(l)]*2)):t=min(b,m);c+=a*t;m-=t
print(c)

Solution (Python):
f=lambda:map(int,input().split());n,m=f();c=0
for a,b in sorted(list(f())for _ in range(n)):t=min(b,m);c+=a*t;m-=t
print(c)

Solution (Python):
f=lambda:map(int,input().split())
n,m=f()
l=sorted(list(f()) for _ in range(n))
c=0
for a,b in l:
  if b>m: c+=a*m; break
  c+=a*b; m-=b
print(c)

Solution (Python):
f=lambda:map(int,input().split())
n,m=f()
l=[]
for _ in range(n):
  l+=[tuple(f())]
l.sort()
c=0
for a,b in l:
  if b<m:
    m-=b
    c+=a*b
  else:
    c+=a*m
    break
print(c)

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

a.sort()

c = 0
for i in range(n):
  x = min(m,a[i][1])
  c += x * a[i][0]
  m -= x
  if m == 0 :
    break

print(c)

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

ans = 0

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

print(ans)

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

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

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

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

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

A.sort()
sm = 0
cnt = 0

i = 0
while sm != M:
	cnt += A[i][0]*min(A[i][1],M-sm)
	sm += min(A[i][1],M-sm)
	i += 1

print(cnt)

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

lis = []

for _ in range(n):
    a,b = map(int, input().split())
    lis.append([a,b])
    
lis = sorted(lis)

total = 0
cash = 0

for i in range(n):
    if total < m:
        total += lis[i][1]
        cash += lis[i][0] * lis[i][1]
        if total >= m:
            total -= lis[i][1]
            cash -= lis[i][0] * lis[i][1]
            for j in range(lis[i][1]):
                while total < m:
                    total += 1
                    cash += lis[i][0]
    else:
        break

print(cash)

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

num, cost = 0, 0
for a, b in AB:
    if num + b > m:
        b = m - num

    num += b
    cost += a * b

    if num == m:
        break

print(cost)

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

tpls = []
for i in range(N):
    a,b = map(int, input().split())
    tpls.append((a, b))
tpls.sort()
need = 0
now = 0
idx = 0
while now < M:
    a, b = tpls[idx]
    if now + b > M:
        need += a * (M - now)
        now = M
    else:
        need += a*b
        now += b
    idx += 1
print(need)

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

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

print(ans)

Solution (Python):
n,m=map(int,input().split())
t=[0]*n
ans=0
temp=0
for i in range(n):
  at,bt=map(int,input().split())
  t[i]=[at,bt]
t.sort()
i=0
while True:
  if temp+t[i][1]>=m:
    ans=ans+t[i][0]*(m-temp)
    break
  else:
    ans=ans+t[i][0]*t[i][1]
    temp=temp+t[i][1]
    i=i+1
print(ans)

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

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

ans=0
for i in range(n):
    c=ab[i][1]
    if c<m:
        ans+=ab[i][0]*c
        m-=c
    else:
        ans+=ab[i][0]*m
        print(ans)
        sys.exit()

Solution (Python):
N,M,*L=map(int,open(0).read().split());C=0
for a,b in sorted(zip(*[iter(L)]*2)):C+=a*min(M,b);M=max(M-b,0)
print(C)

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

ans=0
countM=0
for a,b in ab:
    b=min(b,M-countM)
    a*=b
    ans+=a
    countM+=b
    if countM==M:
        break

print(ans)

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

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

s_A = sorted(A)

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

Solution (Python):
import sys

N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				sys.exit()
print(ans)

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

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

ans = 0
honsu = 0

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

print(ans)

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

Solution (Python):


n, m = map(int, input().split())
a = [-1 for _ in range(n)]
b = [-1 for _ in range(n)]
d = {}
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] not in d:
        d[a[i]] = b[i]
    else:
        d[a[i]] += b[i]

d = sorted(d.items(), key=lambda x:x[0])
num = ans = 0 
for i in range(len(d)):
    tmp = num 
    num += d[i][1]
    if num <= m:
        ans += d[i][0]*d[i][1]
    else:
        ans += d[i][0]*(m-tmp)
        break

print(ans)

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

l.sort()

drink = 0
shop = 0
money = 0
while drink < m:
  if l[shop][1] == 0:
    shop += 1
  else:
    drink += 1
    money += l[shop][0]
    l[shop][1] -= 1
"""    
    print("shop:",shop)
    print("drink:",drink)
    print("money:",money)
"""
print(money)

Solution (Python):
import sys
import math
import itertools
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n, m = I2()
a = [Intl() for i in range(n)]
a.sort()
i = 0
c = 0
s = 0
while s < m:
    s += a[i][1]
    c += a[i][0]*a[i][1]
    i += 1
i -= 1

print(c-a[i][0]*(s-m))

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

Solution (Python):






from collections import deque



n,m=map(int,input().split())
b=[list(map(int,input().split())) for _ in range(n)]
res=0
ans=0
b.sort(key=lambda x: x[0])
for i in range(n):
    if res+b[i][1]<=m:
        ans+=b[i][0]*b[i][1]
        res+=b[i][1]
    else:
        ans+=b[i][0]*(m-res)
        break
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
count=0
while(count<N):
  if AB[count][1]<=M:
    ans+=AB[count][0]*AB[count][1]
    M-=AB[count][1]
    count+=1
  else:
    ans+=AB[count][0]*M
    break
print(ans)

Solution (Python):
import sys

N, M = map(int, input().split())
shop = []
count = 0
money = 0
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])

shop = list(sorted(shop))

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]

ab.sort()

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

Solution (Python):
n,m=map(int,input().split())
num=[]
for i in range(n):
    a,b=map(int,input().split())
    num.append([a,b])
str1= lambda val: val[0]
num.sort(key=str1)
numa=0
numb=0
for i in range(n):
    numa+=(num[i][1])*(num[i][0])
    numb+=num[i][1]
    if numb>=m:
        numa-=(numb-m)*num[i][0]
        break
print(numa)

Solution (Python):

import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(input()))



def inlist():
    return(list(map(int, input().split())))



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


n, m = invr()
A = []
for i in range(n):
    A.append(inlist())

A = sorted(A, key=lambda d: d[0])
res = 0
for a in A:
    if m == 0:
        break
    if a[1] >= m:
        res += a[0] * m
        m = 0
    else:
        res += a[0] * a[1]
        m -= a[1]
print(res)

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

Solution (Python):


n,m = map(int,input().split(" "))
li = []

for i in range(n):
    a,b = map(int,input().split(" "))
    li.append((a,b))

li.sort()

result = 0
count = 0
flag = False
for i in range(m):
    for j in range(li[i][1]):
        result += li[i][0]
        count += 1
        if count == m:
            flag = True
            break
    if flag:
        break
print(result)

Solution (Python):
def inpl(): return list(map(int, input().split()))
N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: -x[0])
ans = 0
while M:
    a, b = X.pop()
    buy = min(M, b)
    ans += a*buy
    M -= buy
print(ans)

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

A = [None] * N
B = [None] * N

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

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

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

print(ans)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    drink = [[int(a) for a in input().split()] for _ in range(N)]
    drink.sort()
    price = 0
    for i in range(N):
        a, b = drink[i]
        if b <= M:
            price += a * b
            M -= b
        else:
            price += a * M
            break
    print(price)

    return  0

if __name__ == "__main__":
    solve()

Solution (Python):
n,m = map(int,input().split())
energy = sorted([tuple(map(int,input().split())) for _ in range(n)])
ret = 0
ind = 0
while(m):
  a,b = energy[ind]
  if b > m:
    ret += a * m
    m = 0
  else:
    ret += a * b
    m -= b
  ind += 1
print(ret)

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

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

AB.sort()

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

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

array = []
[array.append(list(map(int,input().split()))) for x in range(n)]

total = 0

array.sort()

for yen,num in array:
    if num < m:
        total += yen*num
        m -= num
    else:
        total += yen*m
        break
print(total)

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

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

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


for n in range(N):
    C[n][0], C[n][1] = map(int,input().split())

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

Solution (Python):


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

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

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

ans = 0
for i in range(m):
    a, b = ab[i]
    if b-m >= 0:
        ans += a*m
        print(ans)
        exit()
    else:
        m -= b
        ans += a*b

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

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

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

a.sort()
cnt=0
ans=0
for i in range(n):
    m-=a[i][1]
    if m>=0:
        ans+=a[i][0]*a[i][1]
    else:
        ans+=(m+a[i][1])*a[i][0]
        print(ans)
        exit()
print(ans)

Solution (Python):
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    AB = [None] * N
    for i in range(N):
        AB[i] = tuple(map(int, input().split()))

    AB.sort(key=itemgetter(0))
    ans = 0
    n_buy = 0
    for A, B in AB:
        if n_buy + B < M:
            n_buy += B
            ans += A * B
        else:
            ans += A * (M - n_buy)
            break

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

tmp = [0]
for i in range(n):
  tmp[0] = input().split()
  cost[i] = int(tmp[0][0])
  lim[i] = int(tmp[0][1])
  
ab = zip(cost,lim)
x = sorted(ab)
a,b = zip(*x)

buy = 0
c = 0
temp = [0]*2
for i in range(0,len(a)):
  
  if(b[i] >= m):
    buy = buy + a[i]*m
    
    break
  else:
    buy = buy + b[i]*a[i] 
    
    m = m - b[i]
    
    

print(buy)

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)

vdic = {}

for i in range(N):
  if A[i] not in vdic.keys():
    vdic[A[i]] = B[i]
  else:
    vdic[A[i]] += B[i]
    
Vdic = sorted(vdic.items())
    
count = 0
cost = 0
    
for i in range(len(Vdic)):
  if Vdic[i][1] + count >= M:
    cost += (M - count) * Vdic[i][0]
    break
  else:
    cost += Vdic[i][1] * Vdic[i][0]
    count += Vdic[i][1]
    
print(cost)

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

Solution (Python):
import sys


def input():
    return sys.stdin.readline().strip()


N, M = map(int, input().split())
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
    if M > B:
        ans += A * B
        M -= B
    else:
        ans += A * M
        break
print(ans)

Solution (Python):
N, M = map(int, input().split())
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
    if M > B:
        ans += A * B
        M -= B
    else:
        ans += A * M
        break
print(ans)

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

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

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

money = 0
ct = M
for i in AB:
    money += min(ct, i[1]) * i[0]
    ct = ct - min(ct, i[1])
    if ct == 0:
        break
print(money)

Solution (Python):
def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    
    ans = 0
    i = m
    for a, b in  sorted(ab):
        if i >= 0:
            ans += a * min(i, b)
            i -= min(i, b)
    
    print(ans)
            

if __name__ == '__main__':
    main()