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):
import sys
input=sys.stdin.readline

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

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

A.sort()
ans = 0
for a,b in A:
    if M == 0:
        break
    n = M if M <= b else b
    M -= n
    ans += n * a
print(ans)

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

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

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

x = 0
for a in A:
    if M == 0:
        break
    while a[1] > 0:
        a[1] -= 1
        M -= 1
        x += a[0]
        if M == 0:
            break
print(x)

Solution (Python):

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

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

total = 0
remain = M
for x in A:
    yen, num = x
    purchase = min(num, remain)
    total += (yen * purchase)
    remain -= purchase
    if remain == 0:
        print(total)
        exit()

Solution (Python):
n,m = map(int,input().split())
ab = [0] * n
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    ab[i]= (a,b)
ab.sort()

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

print(ans)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N,M = II()
A,B = Line(N)
c = []
for i in range(N):
    c.append([A[i],B[i]])

c.sort()
ans = 0
count = 0

for i in range(N):
    x = min(c[i][1], M-count)
    ans += x*c[i][0]
    count += x
    if count==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(key=lambda x: x[0])


count = 0
cost = 0
for a, b in AB:
    if count + b <= M:
        count += b
        cost += a * b
    else:
        diff = M - count
        count += diff
        cost += a * diff

    if count == M:
        break

print(cost)

Solution (Python):
a,b,c,d=list(map(int,input().split())),[],0,0
for i in range(a[0]):
    b.append(list(map(int,input().split())))
b.sort()
for i in range(a[1]):
    c+=b[d][0]
    b[d][1]-=1
    if b[d][1]==0:
        d+=1
print(c)

Solution (Python):
n, m = map(int, input().split())
drink = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a in drink:
        drink[a] = drink[a]+b
    else:
        drink[a] = b
drink = list(drink.items())
drink.sort()

num = m
cost = 0
for i in range(n):
    p = min(num, drink[i][1])
    cost += drink[i][0]*p
    num -= p
    if num == 0:
        break
print(cost)

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

sum1 = 0
left = M 
for i in range(N):
    a,b = Data[i]
    if left <= b:
        sum1 += a * left 
        break
    else:
        sum1 += a * b
        left -= b

print(sum1)

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

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

ans = 0

for j,k in x:
	if k<m:
		ans += j*k
		m -= k
	else:
		ans += j*m
		break
print(ans)

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

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

c = 0
ans = 0
for i,j in AB:
  c += j
  if c < m:
    ans += i*j
  else:
    ans += i*(m-(c-j))
    break

print(ans)

Solution (Python):
n,m=map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
 
l.sort()
a=0
ans=0
for i,j in l:
    for k in range(int(j)):
        if a>=m:
            break
        else:
            ans+=int(i)
            a+=1
 
print(ans)

Solution (Python):
from sys import stdin

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

l.sort()
ans=0
for i,j in l:
    a=min(m,int(j))
    ans+=a*int(i)
    m-=a
print(ans)

Solution (Python):
N,M = map(int,input().split())
li = [list(map(int,input().split())) for i in range(N)]
li=sorted(li,key=lambda x: x[0])
m_sum=0
for i in li:
	buy=min(M,i[1])
	m_sum+=i[0]*buy
	M-=buy
print(m_sum)

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

list.sort()
ans = 0

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

print(ans)

Solution (Python):

n,m=map(int,input().split())
A=[[0 for i in range(2)] for j in range(n)]
ans=0

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

A.sort()

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

Solution (Python):

from heapq import heappop, heappush
n, m = [int(el) for el in input().split(' ')]
X =[]
for i in range(n):
    a, b = [int(el) for el in input().split(' ')]
    heappush(X, (a,b))
total = 0
price = 0
for i in range(n):
    a, b = heappop(X)
    if total + b < m:
        price += a*b
        total += b
    else:
        price += a*(m-total)
        print(price)
        break

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

s=sorted(s,key=lambda x:x[0])
cost=0
for i in range(n):
  if m>s[i][1]:
    m-=s[i][1]
    cost+=s[i][0]*s[i][1]
  else:
    cost+=s[i][0]*m
    m=0
print(cost)

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

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

Solution (Python):
from collections import defaultdict as dd


INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*args):
    return tuple(p(v) for p, v in zip(args, input().split()))


def main():
    N, M = parse(int, int)

    AB = dd(int)
    for _ in range(N):
        a, b = map(int, input().split())  
        AB[a] += b
    shops = sorted(AB.keys())

    m, cost = M, 0
    for price in shops:
        count = AB[price]
        if m <= count:
            cost += price * m
            break
        else:
            cost += price * count
            m -= count
    print(cost)

main()

Solution (Python):
from collections import defaultdict as dd


INF = float("inf")
MOD = int(1e9 + 7)
def int1(n):
    return int(n) - 1
def parse(*args):
    return tuple(p(v) for p, v in zip(args, input().split()))


def main():
    N, M = parse(int, int)

    AB = dd(int)
    for _ in range(N):
        a, b = parse(int, int)
        AB[a] += b
    shops = sorted(AB.keys())

    m, cost = M, 0
    for price in shops:
        count = AB[price]
        if m <= count:
            cost += price * m
            break
        else:
            cost += price * count
            m -= count
    print(cost)

main()

Solution (Python):
from sys import stdin
import math

N,M = [int(x) for x in stdin.readline().rstrip().split()]
ab_dict = {}
amount = 0
money = 0

for _ in range(N):
  a,b = [int(x) for x in stdin.readline().rstrip().split()]
  if a in ab_dict: ab_dict[a] += b
  else: ab_dict[a] = b

ab_dict = sorted(ab_dict.items())

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

print(money)

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

ab.sort()
sum_money = 0
for i in range(n):
    if m > ab[i][1]:
        sum_money += ab[i][0]*ab[i][1]
        m -= ab[i][1]
    else:
        sum_money += ab[i][0]*m
        break

print(sum_money)

Solution (Python):
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append([a,i])
    B.append(b)
A.sort()
i=0
ans=0
l=0
while True:
    l+=B[A[i][1]]
    if m>l :
        ans+=A[i][0]*B[A[i][1]]
    elif l==m:
        ans+=A[i][0]*B[A[i][1]]
        break
    else:
        ans+=A[i][0]*B[A[i][1]]-(l-m)*A[i][0]
        break
    i+=1
print(ans)

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

ab.sort()
rem = m
ans = 0

for a, b in ab:
    if rem <= b:
        ans += a * rem
        break
    else:
        ans += a * b
        rem -= b

print(ans)

Solution (Python):
n, m = map(int, input().split())
s = [list(map(int,input().split())) for _ in range(n)]
ans = 0
ss = sorted(s)

for i in range(n):
    if ss[i][1] - m < 0:
        v = ss[i][0]*ss[i][1]
        ans += v
        m -= ss[i][1]
        if m == 0:
            break
        
    elif ss[i][1] - m >= 0:
        v = ss[i][0]*m
        ans += v
        m -= m
        if m == 0:
            break

print(ans)

Solution (Python):
def solve():
    n, m = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
    count, spend = 0, 0
    for a, b in ab:
        if count + b > m:
            spend += a * (m - count)
            break
        else:
            spend += a * b
            count += b
    return spend


if __name__ == "__main__":
    print(solve())

Solution (Python):
n, m = map(int, input().split())
amount = 0
money = 0
ab = [list(map(int, input().split())) for _ in range(n)]
sorted_ab = sorted(ab)
for i in range(n):
  if amount > m:
    break
  amount += sorted_ab[i][1]
  money += sorted_ab[i][0] * sorted_ab[i][1]
  if amount > m:
    money -= (sorted_ab[i][0] * (amount - m))
  
print(money)

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

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

D.sort()
num = 0
cost = 0
i = 0
while num < M:
    cost += D[i][0] * min(D[i][1], M - num)
    num += min(D[i][1], M - num)
    i += 1

print(cost)

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

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

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

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

l.sort()

for i, j in l:
    if j >= m:
        sum += i * m
        m = 0
    else:
        sum += i * j
        m -= j
    if m == 0:
        break

print(sum)

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

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

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

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

Solution (Python):
N, M = map(int, input().split())
shops = [None] * N
for i in range(N):
  shops[i] = list(map(int, input().split()))
shops.sort()
cnt = 0
ans = 0
while cnt < M:
  shop = shops.pop(0)
  if cnt + shop[1] >= M:
    ans += (M - cnt) * shop[0]
    cnt = M
  else:
    ans += shop[0] * shop[1]
    cnt += shop[1]
print(ans)

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

for i in range(n):
    if m > li[i][1]:
        an+=li[i][0]*li[i][1]
        m-=li[i][1]
    else:
        an+=m*li[i][0]
        print(an)
        exit()

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])
    if len(li3)>M:
        break
print(sum(li3[0:M]))

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

ab.sort()
need_energy = m
answer = 0
for i in range(n):
    if need_energy <= ab[i][1]:
        answer += ab[i][0]*need_energy
        break
    else:
        answer += ab[i][0]*ab[i][1]
        need_energy -= ab[i][1]

print(answer)

Solution (Python):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
ta = 0
tc = 0
for i in range(len(a)):
    tc += min(m, a[i][1])
    ta += min(m, a[i][1]) * a[i][0]
    m -= min(m, a[i][1])
    if m == 0:
        print(ta)
        exit()

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

ans = 0
for x,y in drinks:
	if y < m:
		ans += x*y
		m -= y
	else:
		ans += x*m
		break

print(ans)

Solution (Python):
def resolve():
    N,M = map(int,input().split())
    AB = []
    for i in range(N):
        a = list(map(int,input().split()))
        AB.append(a)
    AB.sort()
    yen,sum = 0,0
    for i in range(N):
        tmp = min(AB[i][1],M-sum)
        yen += tmp*AB[i][0]
        sum += tmp
        if (sum>=M):
            break
    print(yen)
resolve()

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


    AB.sort()


    yen = 0
    sum = 0
    for i in range(N):

        tmp = min(AB[i][1],M-sum) 
        yen += tmp*AB[i][0]
        sum += tmp
        if (sum>=M):
            break
    print(yen)
resolve()

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

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

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

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

shop = sorted(ab)


count = 0
rest = m
price = 0

for i in range(n):
    
    
    if rest == 0:
        break

    num = shop[i][1]

    if num < rest:
        price += shop[i][0] * shop[i][1]
        rest = rest - shop[i][1]

    else:
        price += shop[i][0] * rest
        break

print(price)

Solution (Python):
n,m = map(int,input().split())
a=[]
b=[]
ab=[]
for i in range(n):
  a0,b0 = map(int,input().split())
  ab.append([a0,b0])
ab.sort()
money = 0
i = 0
while m > 0:
  money+=min(m,ab[i][1])*ab[i][0]
  m-=min(m,ab[i][1])
  i+=1
print(money)

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

n,m=map(int,input().split())
ans=0
s=[[0,0] for _ in range(n)]
for i in range(n):
        s[i][0],s[i][1]=map(int,input().split())
s.sort()
for i in range(n):
        if m>=s[i][1]:
                ans+=s[i][0]*s[i][1]
                m-=s[i][1]
        else:
                ans+=s[i][0]*m
                break


print(ans)

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

h=0
s=0
t=0
for i in range(n):
    h += L[i][1]
    if h >= m:
        t=h-m
        s=i
        break
r=0
for j in range(s+1):
    r += L[j][0]*L[j][1]
r -= t*L[s][0]
   
print(r)

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

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

ans=0
buy = 0
buy_sum = 0

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

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

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

Solution (Python):
N, M = map(int, input().split())
ABs = []
for i in range(N):
  A, B = map(int, input().split())
  ABs.append((A, B))
ABs.sort(key=lambda AB: AB[0])

r = 0
m = 0
for i in range(N):
  A, B = ABs[i]
  if m+B >= M:
    r += A*(M-m)
    break
  else:
    r += A*B
    m += B
print(r)

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

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

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

dd=sorted(d)   
ans=0
for i in range(n):
    if dd[i][1]<m:
        ans+=dd[i][0]*dd[i][1]
        m-=dd[i][1]
    
    else:
        ans+=int(dd[i][0]*m)
        print(ans)
        exit()

Solution (Python):
n,m = map(int,input().split())
lis = []
for i in range(n):
    info = list(map(int,input().split()))
    lis.append(info)
lis = sorted(lis)
mazai = 0
money = 0
for i in range(n):
    buy = min(lis[i][1], m-mazai)
    money += lis[i][0] * buy
    mazai += buy
    if mazai == m:
        break
print(money)

Solution (Python):


def main():

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

    for i in stDrinkList:
        if M-i[1] <= 0:
            ans +=M*i[0]
            print(ans)
            exit()

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


    






    
if __name__== "__main__":
    main()

Solution (Python):



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


ab_list.sort(key=lambda val: val[0])
nokori = m
cost = 0

for a, b in ab_list:
    if nokori < b:
        cost += a * nokori
        break
    else:
        cost += a * b
        nokori -= b

print(cost)

Solution (Python):
N, M = map(int, input().split())
Z = [list(map(int, input().split()))for _ in range(N)]
Z = sorted(Z, key=lambda Z: Z[0])
Z.append([0,0])
q = 0
c = 0
for i in range(len(Z)):
    if q < M:
        q += Z[i][1]
        c += Z[i][0]*Z[i][1]
    else:
        c -= (q- M)* Z[i-1][0]
        print(c)
        exit()

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

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

nokori = M
res = 0
for s in stores:
    cnt = nokori if nokori - s[1] < 0 else s[1]
    res += cnt * s[0]
    nokori -= cnt
    if nokori <= 0: break
print(res)

Solution (Python):

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

rest, res = m, 0

for i in range(n):
    buy = min(rest, drinks[i][1])
    res += buy * drinks[i][0]
    rest -= buy

print(res)

Solution (Python):

import sys


def get_num():
    return int(input())


def get_nums(n):
    res = [0 for _ in range(n)]
    for i in range(n):
        res[i] = int(input())
    return res


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

n, m = get_numbers()

stores = list()
for _ in range(n):
    a, b = get_numbers()
    stores.append((a, b))

cost = 0
for a, b in sorted(stores, key=lambda x: x[0]):
    num = min(b, m)
    cost += num * a
    m -= num
    if m == 0:
        break

print(cost)

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

store = sorted(store)

money = 0
items = 0

for i in range(len(store)):
    if items + store[i][1] >= m:
        money += store[i][0] * (m - items)
        break
    money += store[i][0] * store[i][1]
    items += store[i][1]

print(money)

Solution (Python):
import sys
n, m = list(map(int, input().split()))
aaa = []
bbb = []
for i in range(n):
  a, b = list(map(int, input().split()))
  aaa.append(a)
  bbb.append(b)
c = zip(aaa, bbb)
c = sorted(c)
aaa, bbb = [list(x) for x in zip(*c)]
num = 0
ans = 0
for i in range(n):
  if num + bbb[i] >= m:
    ans += (m - num) * aaa[i]
    print(ans)
    sys.exit()
  else:
    ans += aaa[i] * bbb[i]
    num += bbb[i]

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

def main():
    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
    rest = M
    for i in range(N):
        a, b = ab[i]
        if b <= rest:
            ans += a * b
            rest -= b
        else:
            ans += a * rest
            break
    print(ans)


if __name__ == "__main__":
    main()

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

AB.sort()

count = 0
money = 0
i = 0

while count < M:
    money += AB[i][0] * AB[i][1]
    count += AB[i][1]
    i += 1

if count > M:
    tmp = count - M
    money -= AB[i-1][0]*tmp

ans = money
print(ans)

Solution (Python):
i=0
n,m=map(int,input().split())
arr=[]
while (i<n):
	a,b=map(int,input().split())
	arr.append([a,b])
	i+=1

arr.sort(key=lambda x:x[0])
s=0
money=0
i=0
left=m
while(left>0):
	if(arr[i][1]<left):
		left-=arr[i][1]
		money+=arr[i][1]*arr[i][0]
	else:
		money+=left*arr[i][0]
		left-=arr[i][1]
	i+=1

print(money)

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

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

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

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

li.sort()
for l in li:
    if M - dr > l[1]:
        dr += l[1]
        mn += l[0] * l[1]
    else:
        mn += l[0] * (M - dr)
        break

print(mn)

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):
    buy = min(m, l[i][1])
    ans += l[i][0]*buy
    m -= buy
    if m == 0:
        break

print(ans)

Solution (Python):
N, M = map(int, input().split())
ab_list = [list(map(int, input().split())) for _ in range(N)]
ab_list.sort(key=lambda i: i[0])
count = 0
money = 0
for a, b in ab_list:
    buy = min(b, M - count)
    count += buy
    money += buy * a
    if count == M:
        break
print(money)

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

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

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

money = 0
n_dri = 0
for i in range(len(ab)):
    mon_num = ab[i]
    if n_dri + mon_num[1] < m:
        money += mon_num[0] * mon_num[1]
        n_dri += mon_num[1]
    else:
        money += mon_num[0] * (m - n_dri)
        print(money)
        exit()

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	n,m = map(int,input().split())
	ab = defaultdict(int)
	for i in range(n):
		tmp =  list(map(int,input().split()))
		ab[tmp[0]]  += tmp[1]
	ab = list(reversed(sorted(ab.items(), key=lambda x:x[0])))
	ans = 0
	while m > 0:
		t = ab.pop()
		ans += t[0] * min(t[1],m)
		m-=t[1]
	print(ans)


def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Solution (Python):
N,M=map(int,input().split())
li=[list(map(int,input().split()))for _ in range(N)]
li.sort()
n=0
price=0
for i ,j in li:
  n+=j
  price+=i*j
  if n>M:
    price-=i*(n-M)
    break
print(price)

Solution (Python):
"""


 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())


 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [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
from itertools import accumulate

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

mod = 1000000007

if __name__ == "__main__":
    N,M = map(int, sys.stdin.readline().split())
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
    s = sorted(l,key=lambda x:x[0])
    n=0
    for i in range(N):
        if M - s[i][1] > 0:
            M=M - s[i][1]
            n += s[i][0]*s[i][1]
        else:
            n += s[i][0]*M
            break
    print(n)

Solution (Python):
def main45():
    data = input().split()
    nm = []
    for i in range(2):
        nm.append(int(data[i]))
    ab = []
    for i in range(nm[0]):
        karid = input().split()
        karin = []
        for j in range(2):
            karin.append(int(karid[j]))
        ab.append(karin)
    ab.sort()
    result = 0
    kazu = 0
    while(nm[1]>0):
        if nm[1] <= ab[kazu][1]:
            result = result + nm[1] * ab[kazu][0]
            nm[1] = 0
        else:
            result = result + ab[kazu][1] * ab[kazu][0]
            nm[1] = nm[1] - ab[kazu][1]
            kazu = kazu + 1
    print(result)

if __name__ == "__main__":
    main45()

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

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


i = 0
while M != 0:
  if AB_sort[i][1] <= M:
    cost += AB_sort[i][0] * AB_sort[i][1]
    M -= AB_sort[i][1]
  else:
    cost += AB_sort[i][0] * M
    M = 0
  i += 1

print(cost)

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

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

import numpy as np

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

cnt=0
amt=0

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

print(amt)

Solution (Python):


import sys
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
m=hoge[1]

a=[]
for i in range(0,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	a.append((hoge[0],hoge[1]))
a.sort()


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




print(total)

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

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

drink.sort(reverse=True)

ans = 0
while m > 0:
    a, b = drink.pop()
    if m > b:
        ans += a * b
        m -= b
    else:
        ans += a * m
        m = 0

print(ans)