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 = []

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

AB.sort()

ans = 0
cnt = 0

for ab in AB:
    for b in range(ab[1]):
        ans += ab[0]
        cnt += 1
        if cnt==M:
            break
    if cnt==M:
        break

print(ans)

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

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB=sorted(AB,key=lambda x:x[0])
cnt=0
ans=0
for a,b in AB:
    tmp=cnt
    cnt=min(m,cnt+b)
    ans+=a*(cnt-tmp)
    if cnt==m:
        break
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

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

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

for i in range(N):
  if Shops[i][1] < M:
    cost += Shops[i][0]*Shops[i][1]
    M -= Shops[i][1]
  else:
    cost += Shops[i][0]*M
    print(cost)
    exit()

Solution (Python):


import sys






















def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    L = [lmi() for _ in range(n)]
    L.sort(key=lambda x: x[0])

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


if __name__ == "__main__":
    main()

Solution (Python):
n, m = map(int, input().split())
L = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a not in L:
        L[a] = b
    else:
        L[a] += b
ans = 0
L = sorted(L.items())
for i in L:
    if i[1] >= m:
        ans += i[0] * m
        break
    else:
        m -= i[1]
        ans += i[0] * i[1]
print(ans)

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

Solution (Python):

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

total = 0
drink = 0
for i in range(0,n) :
    drink = drink + l[i][1]
    if drink>m:
        break
    
noko = m-drink

d = i

for j in range(0,d+1):
    total += l[j][0]*l[j][1]
    
total =total + l[d][0]*noko

print(total)

Solution (Python):
n,m = map(int,input().split())
ab_list = [list(map(int,input().split())) for nesya in range(n)]
s_list = sorted(ab_list)
cost = 0
for ab in s_list:
  a = ab[0]
  b = ab[1]
  if b <= m:
    m -= b
    cost += a*b
  else:
    cost += a*m
    m = 0
print(cost)

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):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    import sys
    input = sys.stdin.readline
    n,m=L()
    dic={}
    a=[]
    for i in range(n):
        ai,bi=L()
        if ai not in dic:
            dic[ai]=0
        dic[ai]+=bi
        a.append(ai)
    a=list(set(a))
    a.sort()
    ans=0
    drink=0
    tmp=0
    while drink<m:
        tmp=a.pop(0)
        for i in range(dic[tmp]):
            drink+=1
            ans+=tmp
            if drink>=m:
                break
    print(ans)
    

if __name__ == '__main__':
    main()

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(key=lambda x: x[0])
count = 0
ans = 0
for i in X:
    if M - count > i[1]:
        count += i[1]
        ans += i[0] * i[1]
        
    else:
        x = M - count
        ans += i[0] * x
        break
print(ans)

Solution (Python):

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

shop_s = sorted(shop, key=lambda x: x[0])
price = 0
drink = 0

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

print(price)

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

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

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
k = 0
while m > 0:
    x = min(m, l[k][1])
    ans += l[k][0] * x
    m -= x
    k += 1
print(ans)

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

stores.sort()
total = 0
i = 0
while True:
    if total >= M:
        i -= 1
        break
    total += stores[i][1]
    i += 1

ac = 0
k_count = 0
j = 0
while not j > i:
    if j == i:
        ac += stores[j][0] * (M-k_count)
    else:
        ac += stores[j][0] * stores[j][1]
    k_count += stores[j][1]
    j += 1

print(ac)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, m = Is()
AB = TIR(n)
AB.sort(key=itemgetter(0))
ans = 0
k = 0
for a, b in AB:
    if k+b < m:
        ans += a*b
        k += b
    else:
        ans += a*(m-k)
        print(ans)
        exit()

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    ab = sorted(zip(A, B))
    k = 0
    ans = 0
    for Ai, Bi in ab:
        v = min(M - k, Bi)
        k += v
        ans += Ai * v
        if k >= M:
            break
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    drink = []
    for _ in range(N):
        a, b = map(int, input().split())
        drink.append((a, b))
    drink.sort(reverse=True)
    

    num = 0
    val = 0
    while num < M:
        a, b = drink.pop()
        if num + b <= M:
            num += b
            val += a * b
        else:
            val += a * (M - num)
            num = M
    print(val)


if __name__ == "__main__":
    main()

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
k = 0
while m > 0:
    x = min(m, l[k][1])
    ans += l[k][0] * x
    m -= x
    k += 1
print(ans)

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

from operator import itemgetter
ab = sorted(ab,key=itemgetter(0),reverse = False)

vl = 0
dr = 0

for i in range(n):
    if ab[i][1] + dr <= m:
        dr += ab[i][1]
        vl += ab[i][1] * ab[i][0]
    elif (ab[i][1] + dr > m) and dr < m :
        vl += (m-dr) * ab[i][0]
        dr += (m-dr)
        break
print(vl)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

def resolve():
    N,M=pin()
    A=sorted([lispin() for _ in range(N)])
    
    ans=0
    for a in A:
        if a[1]>M:
            ans+=a[0]*M
            break
        else:
            ans+=a[0]*a[1]
            M-=a[1]
        
    print(ans)

resolve()

Solution (Python):
if True:
    n,m=map(int,input().split())
    s=[(0,0) for i in range(n)]
    for i in range(n):
        s[i]=list(map(int,input().split()))
    
else:
    n,m=2,5
    s=[(4,9),(2,4)]
s=sorted(s,key=lambda x: x[0])

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

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

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

lab = list(zip(la, lb))
lab = sorted(lab, key=lambda x: x[0])

cst = 0
i = 0
while M - lab[i][1] > 0:
    M -= lab[i][1]
    cst += lab[i][0]*lab[i][1]
    i += 1

cst += lab[i][0] * M
print(cst)

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

Solution (Python):
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
AB = sorted([LI() for _ in range(N)])
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):
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
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 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()
ans=0
rest=m
for i in range(n):
    ans+=lis[i][0]*min(lis[i][1],rest)
    rest-=min(lis[i][1],rest)
    if rest==0:
        break
print(ans)

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

Solution (Python):
from operator import itemgetter, attrgetter

n, m = list(map(int, input().split(' ')))
abn = [None] * n
for i in range(n):
    abn[i] = list(map(int, input().split(' ')))

abn = sorted(abn, key=itemgetter(0))

cost = 0
num = 0
for ab in abn:
    temp = 0
    while num < m and temp < ab[1]:
        cost += ab[0]
        temp += 1
        num += 1
    if num == m:
        break

print(cost)

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

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

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

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

Solution (Python):
n,m = map(int,input().split())
p,x = 0,0
l = [tuple(map(int,input().split())) for i in range(n)]
l.sort()
for a in l:
    if m-a[1]>=1:
        p+=a[0]*a[1]
        m-=a[1]
    else:
        p+=a[0]*m
        m=0
        break
print(p)

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

ab=[[int(x) for x in input().split()]for j in range(n)]

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


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

Solution (Python):
def main():
    N, M = list(map(int, input().split(' ')))
    shops = list()
    for _ in range(N):
        A, B = list(map(int, input().split(' ')))
        shops.append((A, B))
    shops.sort()
    drink = 0
    money = 0
    for s in shops:
        rest = M - drink
        cnt = min([rest, s[1]])
        drink += cnt
        money += cnt * s[0]
        if drink == M:
            break
    print(money)


if __name__ == '__main__':
    main()

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

amount = 0
for price, num in sorted_drinks:
    if m <= num:
        amount += price*m
        break

    m -= num
    amount += price*num
print(amount)

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

def main():
    n, m = map(int, input().split())

    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

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

    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

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

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

    for i, j in ab:
        if m < j:
            ans += i*m
            break
        m -= j
        ans += i*j
        

    print(ans)

main()

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

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

    for i, j in ab:
        if m >= j:
            m -= j
            ans += i*j
        elif m < j:
            ans += i*m
            break

    print(ans)

main()

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

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

for i, j in ab:
    if m >= j:
        m -= j
        ans += i*j
    elif m < j:
        ans += i*m
        break

print(ans)

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

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

temp = 0
ans = 0
i = 0
while temp < m:
    p = min(s[i][1],m-temp)
    temp += p
    ans += (s[i][0])*p
    i += 1

print(ans)

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

count = 0
mount = 0
pair.sort(key=lambda x:x[0])
temp = 0
for i in range(n):
    mount += pair[i][0]*pair[i][1]
    count += pair[i][1]
    if(count >= m): 
        temp = i
        break

print(mount - (count - m)*pair[temp][0])

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

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

AB.sort()
res=0
cnt=0

for a,b in AB:
	if cnt+b<m:
		cnt+=b
		res+=a*b
	else:
		res+=a*(m-cnt)
		break

print(res)

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

def main():
    N, M = map(int, readline().rstrip().split())
    AB = [tuple(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort()
    pro = 0
    cost = 0
    for a, b in AB:
        if pro + b >= M:
            cost += (M - pro) * a
            break
        pro += b
        cost += a * b
    
    print(cost)


if __name__ == '__main__':
    main()

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

def main():
    N, M = map(int, readline().rstrip().split())
    AB = [list(map(int, readline().rstrip().split())) for _ in range(N)]
    AB.sort()
    pro = 0
    cost = 0
    for a, b in AB:
        if pro + b >= M:
            cost += (M - pro) * a
            break
        pro += b
        cost += a * b
    
    print(cost)


if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
abs = [list(map(int, input().split())) for _ in range(n)]
abs_sorted = sorted(abs, key=lambda x: x[0])
num = 0
ans = 0
while m != 0:
    a, b = abs_sorted[num][0], abs_sorted[num][1]
    if m >= b:
        ans += a * b
        m -= b
        num += 1
    else:
        ans += a * m
        m = 0
print(ans)

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

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

S=sorted(AB)
D=[]
check=0
ans=0
for i in range(N):
    check+=S[i][1]
    if check<=M:
        D+=[S[i][1]]
    else:
        b=check-M
        D+=[S[i][1]-b]
        break
for i in range(len(D)):
    ans+=D[i]*S[i][0]
print(ans)

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

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

ans=0
for c in cost_li:
    if m==0:
        break
    if m<c[1]:
        ans+=c[0]*m
        break
    ans+=c[0]*c[1]
    m-=c[1]
print(ans)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())




n,m = map (int,input().split())
a = [0] * n
b = [0] * n
box = [0] * n
for i in range(n):
    a[i],b[i] = map(int,input().split())
    box[i] = [a[i],b[i]]
box.sort(key = lambda x:x[0])
s = 0
ans = 0
while m > 0:
    
    m -= box[s][1]
    ans += box[s][0] * box[s][1]
    s += 1

print(ans - (-m) * box[s - 1][0])

Solution (Python):

import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    C = sorted(zip(A, B))
    ans = 0
    for a, b in C:
        if b >= M:
            return ans + a * M
        ans += a * b
        M -= b
    raise



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    print(solve(N, M, A, B))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

a_b.sort()
sum_,all_ = m,0
for j in range(n):
  if sum_>=a_b[j][1]:
    sum_-=a_b[j][1]
    all_+=a_b[j][1]*a_b[j][0]
  elif sum_<a_b[j][1]:
    all_+=sum_*a_b[j][0]
    sum_-=sum_
print(all_)

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

Solution (Python):
import sys
n,m = map(int,input().split())
d = [None]*n
for i in range(n):
    a,b = map(int,input().split())
    d[i] = [a,b]

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            print(ryoukin)
            sys.exit()

Solution (Python):
import sys
n,m = map(int,input().split())
d = [None]*n
for i in range(n):
    a,b = map(int,input().split())
    d[i] = [a,b]

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            print(ryoukin)
            sys.exit()

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

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            print(ryoukin)
            exit()

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

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            print(ryoukin)
            exit()

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    n, m = 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 a, b in ab:
        if m - b > 0:
            m -= b
            ans += a * b
        elif m - b == 0:
            m -= b
            ans += a * b
            break
        else:
            ans += a * m
            break

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 5
4 9
2 4"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4 30
6 18
2 5
3 10
7 9"""
        output = """130"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1 100000
1000000000 100000"""
        output = """100000000000000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            break
    else:
        continue
    break    

print(ryoukin)

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

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

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            break
    if cnt == m:
        break    
print(ryoukin)

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

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

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

money=0

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


print(money)

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

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

money=0

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

    if m==0:
        break

print(money)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
l.sort()
i = 0
count = 0
money = 0
while count < m:
  count += l[i][1]
  money += l[i][0]*l[i][1]
  i += 1
i -= 1
if count > m:
  money -= (count-m)*l[i][0]
print(money)

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

money = 0
buy = 0

for i in range(n):
    if buy < m:
        money += ab[i][0]*min(ab[i][1], m-buy)
        buy += min(ab[i][1], m-buy)
    if buy == m:
        break
print(money)

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

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

for _ in range(N):
    Ai, Bi = map(int, input().split())
    AB.append((Ai, Bi))

AB = sorted(AB)
ans = 0
num = 0

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

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

Solution (Python):




from operator import itemgetter 






ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(n,m,l):
    res = 0
    count = 0
    l = sorted(l,key=itemgetter(0))
    for a,b in l:
        if count + b < m:
            res += a * b
            count += b
            continue
        else:
            res += a * (m-count)
            count += (m-count)
    return res

n,m = mi()
l = mix(n)
print(main(n,m,l))

Solution (Python):
import numpy as np

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

a = np.array(a, dtype='int64')
a = a[a[:, 0].argsort(), :]

mysum = 0
coin = 0
for c in a:
    if mysum + c[1] < M:
        mysum += c[1]
        coin += c[0] * c[1]
    else:
        d = M - mysum
        coin += d * c[0]
        break

print(coin)

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

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

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

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