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
import math
import heapq


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


def main():
    N, M = map(int, input().split())

    D = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(D, (a, b))
    ans = 0
    while M > 0:
        a, b = heapq.heappop(D)
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += M * a
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math
import heapq


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


def main():
    N, M = map(int, input().split())

    D = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(D, (a, b))
    ans = 0
    while M > 0:
        a, b = heapq.heappop(D)
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += M * a
            print(ans)
            exit()


if __name__ == "__main__":
    main()

Solution (Python):
from heapq import heappush,heappop
n,m=map(int,input().split())
d=[]
for i in range(n):
  a,b=map(int,input().split())
  heappush(d,(a,b))
ans=0
while d:
  a,b=heappop(d)
  if m>b:
    ans+=a*b
    m-=b
  else:
    ans+=a*m
    break
print(ans)

Solution (Python):
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
a,b = [list(i) for i in zip(*l)]
j = 0
p = 0

while m > 0:
    if b[j] <= m:
        p += a[j] * b[j]
        m -= b[j]
        j += 1
    else:
        p += a[j] * m
        m = 0

print(p)

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

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

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

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

count = 0
cost = 0
shop = 0
while count < M:
  buy = min(Z[shop][1], M - count)
  count += buy
  cost +=  buy * Z[shop][0]
  if count < M:
    shop += 1
  
print(cost)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = map(int, input().split())
    all = []
    for i in range(n):
        all.append(list(map(int, input().split())))
    all.sort()
    for a,b in all:
        if m >= b:
            m -= b
            ans += a*b
        else:
            ans += a*(m)
            break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m = map(int, input().split())
    all = []
    for i in range(n):
        all.append(list(map(int, input().split())))
    all.sort()
    for i in range(n):
        if m >= all[i][1]:
            m -= all[i][1]
            ans += all[i][0]*all[i][1]
        else:
            ans += all[i][0]*(m)
            break
    print(ans)

if __name__ == '__main__':
    main()

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

for i, j in drink:
    if m != 0:
        if m >= j:
            ans += i * j
            m -= j
        else:
            ans += i * m
            break

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])
s = sorted(l, key=lambda x:x[0])
ans = 0
for i in range(n):
  a, b = s[i]
  if b <= m:
    ans += a*b
    m -= b
  else:
    ans += a*m
    break
print(ans)

Solution (Python):
N, M = map(int, input().split())
items = [ tuple(map(int, input().split())) for _ in range(N) ]
items.sort()
ans = 0
m = 0
for item in items:
  a = min(M - m, item[1])
  m += a
  ans += a * item[0]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = list(map(int,input().split()))
ab = sorted([list(map(int,input().split())) for _ in range(n)])
dri_cos = 0

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

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0
ans = 0
inf = float("inf")

n,m = I()
a =[l() for _ in range(n)]

a.sort()
i = 0
while m != 0:
    if a[i][1] >= m :
        ans += m*a[i][0]
        break
    else:
        ans += a[i][0]*a[i][1]
        m -= a[i][1]
        i += 1

print(ans)

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 = sorted(L, key=lambda x: x[0])

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

Solution (Python):
def solve():
  ans = 0
  N, M = map(int, input().split())
  A = [list(map(int, input().split())) for _ in range(N)]
  A.sort()
  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
  return ans
print(solve())

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
AB = []
for i in range(n):
    a,b = readInts()
    AB.append((a,b))
AB = sorted(AB, key = lambda x:x[0])

num = 0
cost = 0
for a,b in AB:
    if m >= num + b:
        num += b
        cost += a*b
    else:
        cost += a*(m - num)
        num = m
print(cost)

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
i = 0
while i<N:
    a,b = A[i]
    if cnt+b<=M:
        cnt += b
        cost += a*b
    else:break
    i += 1
if cnt<M:
    a,b = A[i]
    cost += (M-cnt)*a
print(cost)

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()
ans = 0
for i in range(n):
    if m == 0:
        break
    if m >= drink[i][1]:
        ans += drink[i][0] * drink[i][1]
        m -= drink[i][1]
    else:
        ans += m*drink[i][0]
        m = 0
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()
pay=0
i=0
while m>0:
    pay+=lis[i][0]*min(m,lis[i][1])
    m-=min(m,lis[i][1])
    i+=1
print(pay)

Solution (Python):
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
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):
N,M=map(int,input().split())

D={}
for _ in range(N):
    A,B=map(int,input().split())

    if A in D:
        D[A]+=B
    else:
        D[A]=B

L=[]
for m in D:
    L.append((m,D[m]))

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

S=0
I=0
while M>0:
    (A,B)=L[I]
    B=min(B,M)
    S+=A*B
    M-=B
    I+=1
print(S)

Solution (Python):
import numpy as np
N,M = (int(X) for X in input().split())
Shop = np.zeros((N,2),dtype=int)
for T in range(0,N):
    Shop[T,:] = (np.array([int(X) for X in input().split()]))
Shop = Shop[np.argsort(Shop[:,0])]
Rest = M
Pric = 0
for T in range(0,N):
    Pric += Shop[T,0]*Shop[T,1]
    Rest -= Shop[T,1]
    if Rest<0:
        Pric += Rest*Shop[T,0]
        break
print(Pric)

Solution (Python):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
ans = 0
cnt = 0
for a, b in AB:
  if cnt == M:
    break
  
  if cnt + b <= M:
    ans += a * b
    cnt += b
  else:
    ans += a * (M - cnt)
    cnt += M - cnt

print(ans)

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

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

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

ans = 0
for i in ab:
  t = min(m,i[1])
  ans += i[0]*t
  m -= t
print(ans)

Solution (Python):
N,M = [int(i) for i in input().split()]
store = [[int(i) for i in input().split()] for j in range(N)]
store.sort()
tc = 0
for i in range(N):
    tc += min(store[i][1], M) * store[i][0]
    M -= store[i][1]
    if M <= 0:
        break
print(tc)

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

drinks.sort()

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

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

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

tp_list.sort()

cnt = 0
cost = 0
flg = False
for a, b in tp_list:
    for i in range(b):
        cnt += 1
        cost += a

        if cnt == M:
            flg = True
            break
    
    if flg:
        break

print(cost)

Solution (Python):
import numpy as np

N,M=map(int,input().split())
l=[]
for n in range(N):
    A,B=map(int,input().split())
    temp_l=[A,B]
    l.append(temp_l)
arr=np.array(l,dtype=np.int64)



need=M
ans=0


col_num=0

route=arr[np.argsort(arr[:,col_num])]

for i in range(N):
    if need >= route[i,1]:
        ans+=route[i,0]*route[i,1]
        need-=route[i,1]
        if need==0:
            break
        else:
            continue
    else:
        ans+=route[i,0]*need
        need=0
print(ans)

Solution (Python):
N, M = (int(x) for x in input().split())
L = []
for i in range(N):
  A, B = (int(x) for x in input().split())
  L.append((A,B))
L.sort()
tn = 0
tm = 0
for i in range(N):
  if L[i][1] < M-tn:
    tn += L[i][1]
    tm += L[i][0]*L[i][1]
  else:
    tm += L[i][0]*(M-tn)
    print(tm)
    quit()

Solution (Python):
import numpy as np

def solve():
    cnt = 0
    money = 0
    for i in range(N):
        if cnt >= M:
            break
        if cnt + AB[i][1] >= M:
            money += AB[i][0] * (M - cnt)
            cnt = M   
        else:
            money += AB[i][0]*AB[i][1]
            cnt += AB[i][1]

    print(money)

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

    solve()

Solution (Python):
def resolve():
    N, M = list(map(int, input().split()))
    ls = []
    for _ in range(N):
        a, b = list(map(int, input().split()))
        ls.append([a, b])
    ls = sorted(ls, key=lambda x: x[0])
    ans = 0
    drink = 0
    for i in range(N):
        if drink >= M:
            break
        if drink + ls[i][1] >= M:
            ans += ls[i][0] * (M - drink)
            drink = M
        else:
            ans += ls[i][0] * ls[i][1]
            drink += ls[i][1]

    print(ans)
    return

resolve()

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

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

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

print(total)

Solution (Python):
n,m = [int(x) for x in input().split()];
pair = [];
(a,b) = (int(x) for x in input().split());
pair.append((a,b));
for i in range(1,n) :
    (a,b) = (int(x) for x in input().split());
    pair.append((a,b));


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

sum =0;
i = 0;
while m > 0 :
    if m >= pair[i][1] :
        m = m - pair[i][1];
        sum = sum + pair[i][0] * pair[i][1];
        i = i +1;
    else :
        sum = sum + m*pair[i][0];
        m = 0;

print(sum);

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

print(ans)

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

Solution (Python):
N, M = map(int, input().split())
shops = []
for _ in range(N):
    a, b = map(int, input().split())
    shops.append((a, b))
shops = sorted(shops, key=lambda s: s[0])
m = 0
total = 0
for a, b in shops:
    if m + b >= M:
        total += (M - m) * a
        break
    else:
        total += a * b
        m += b
print(total)

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

total = 0
for shop in shops:
    if M != 0:
        if shop[1] <= M:
            total += shop[0] * shop[1]
            M -= shop[1]
        else:
            total += shop[0] * M
            M = 0
    else:
        break

print(total)

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

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

Solution (Python):
n,m = map(int,input().split())
ab = [ list(map(int,input().split(" "))) for i in range(n)]
ab.sort()
ans = 0
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):
def main():
    N,M = map(int, input().split())
    AB = []
    for i in range(N):
        A,B =  map(int, input().split())
        AB.append((A,B))
    AB.sort()
    coin = 0

    for i in range(N):
        temp = min(M,AB[i][1])
        coin += temp * AB[i][0]
        M -= temp
        if M==0:
            break


    print(coin)


if __name__ == '__main__':
    main()

Solution (Python):
L=list()
R=list()
T=0
N,M=map(int,input().split())
for i in range(N):
  A,B=map(int,input().split())
  L.append(A)
  R.append(B)
c = zip(L, R)
c=sorted(c)
L, R = zip(*c)
L=list(reversed(L))
R=list(reversed(R))
while True:
  c=L[-1]
  T+=c*min(M,R[-1])
  M-=min(M,R[-1])
  L.pop(-1)
  R.pop(-1)
  if M==0:
    break
print(T)

Solution (Python):
from operator import itemgetter
n, m = map(int, input().split())
lst = []
for i in range(n):
  lst.append(tuple(map(int, input().split())))
lst.sort(key=itemgetter(0))
res = 0
for i in range(n):
  if lst[i][1] <= m:
    m -= lst[i][1]
    res += (lst[i][0] * lst[i][1])
  else:
    res += (lst[i][0] * m)
    break
print(res)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
AB = []
for i in range(n):
    a,b = readInts()
    AB.append((a,b))
AB = sorted(AB, key = lambda x:x[0])

num = 0
cost = 0
for a,b in AB:
    if m >= num + b:
        num += b
        cost += a*b
    else:
        cost += a*(m - num)
        num = m
print(cost)

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

price=0
i=0
while m>0:
    price+=lis[i][0]*min(m,lis[i][1])
    m-=min(m,lis[i][1])
    
    i+=1
print(price)

Solution (Python):
from math import ceil
def solve():
    ans = 0
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    A.sort()
    for i in range(N):
        if M<=A[i][1]:
            ans += M*A[i][0]
            break
        else:
            ans += A[i][0]*A[i][1]
            M -= A[i][1]
    return ans
print(solve())

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

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

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

C.sort()

tmp = M
ans = 0
for cost,num in C:
    if tmp - num >= 0:
        tmp -= num
        ans += num*cost
    else:
        ans += cost*tmp
        break

print(ans)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, M = inm()

prices = []
for i in range(N):
    a, b = inm()
    prices.append((a, b))
prices.sort()


def solve():
    cnt = 0
    amount = 0
    for a, b in prices:
        x = min(b, M - cnt)
        amount += x * a
        cnt += x
        if cnt >= M:
            break

    return amount


print(solve())

Solution (Python):
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for a,b in ab:
    if b <= m:
        ans += a*b
        m -= b
    elif b > m:
        ans += m * a
        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 i in range(m):
    a, b = AB[i]
    if b >= m:
        ans += a*m
        break
    else:
        ans += a*b
        m -= b
print(ans)

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

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

Solution (Python):
from bisect import bisect_left
from itertools import accumulate

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

cnt = 0
ans = 0

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

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")


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

Solution (Python):
n, m = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(n)])
i, ans = 0, 0
while ab[i][1] < m:
    m -= ab[i][1]
    ans += ab[i][1] * ab[i][0]
    i += 1
ans += ab[i][0] * m
print(ans)

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

info.sort(key=lambda x:x[0])
ans=0
for a, b in info:
  if M>=b:
    ans+=a*b
    M-=b
  elif M<b and M>0:
    ans+=a*M
    break
  else:
    break
print(ans)

Solution (Python):

N, M = map(int, input().split())
val = []
for n in range(N):
    val.append( list(map(int, input().split())) )
val = sorted(val, reverse=False, key=lambda x: x[0])
ans = 0
for n in range(N):
    if val[n][1] >= M:
        ans += val[n][0] * M
        break
    else:
        ans += val[n][0] * val[n][1]
        M -= val[n][1]
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    a,b = (int(i) for i in input().split())
    A[i] =(a,b)


A.sort()
num_sum =0
price_sum =0
for i in range(N):
    price,num =A[i]
    if num_sum < M -num:
        num_sum  +=num
        price_sum += price *num
    elif num_sum == M -num:
        price_sum +=price *num
        break
    else:
        price_sum +=price*(M -num_sum)
        break
print(price_sum)

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

A_B.sort()
count = 0
money = 0
i = 0
while count != M:
    money += A_B[i][0] * min(M-count, A_B[i][1])
    count += min(M-count, A_B[i][1])
    i += 1
print(money)

Solution (Python):
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n,m = readInts()
ab = [readInts() for i in range(n)]
ab.sort()
i = 0
ans = 0
while m>0:
	if m>=ab[i][1]:
		m-=ab[i][1]
		ans+=ab[i][0]*ab[i][1]
		i+=1
	else:
		ans += m*ab[i][0]
		m = 0
print(ans)

Solution (Python):

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

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

print(ans)

Solution (Python):
import math
N,M = map(int, input().split())
l = [[int(i) for i in input().split()] for j in range(N)]

l.sort()
count = 0
i = 0
while(M > 0):
    M -= l[i][1]
    count += l[i][0]*l[i][1]
    if(M < 0):
        count -= abs(M)*l[i][0]
    i += 1
print(count)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
AB = [LIST() for _ in range(N)]

ans = 0
cnt = 0
AB = sorted(AB, reverse=True)
while cnt < M:
    A, B = AB[-1]
    if cnt+B <= M:
        cnt += B
        ans += A*B
    else:
        ans += A * (M-cnt)
        cnt = M
    AB.pop()
print(ans)

Solution (Python):
N,M = map(int,input().split())
shops = [list(map(int,input().split())) for i in range(N)]
shops.sort()
get = 0
money = 0
for i in range(0,N,1):
    if get == M:
        break
    tmp_buy = min(M-get,shops[i][1])
    get += tmp_buy
    money += tmp_buy*(shops[i][0])
print(money)

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


x.sort()
sum = 0
yen = 0
for i in range(n):
    sum += x[i][1]
    yen += x[i][0] * x[i][1]
    if sum >= m:
        yen -= (sum-m)*x[i][0]
        break

print(yen)

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

drinks=M
cost = 0
for i in D:
    if drinks > i[1]:
        drinks -= i[1]
        cost += i[1] * i[0]
    else:
        cost += (drinks * i[0])
        break

print(cost)

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

D.sort()
ans = 0

while M > 0:
    for i in D:
        if i[1] >= M:
            ans += M*i[0]
            M = 0
        else:
            ans += i[1]*i[0]
            M -= i[1]

print(ans)

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

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

s = 0
for a, b in x:
  if m > b:
    s += a * b
    m += -b
  else:
    s += a * m
    break

print(s)

Solution (Python):
import collections
N,M = map(int,input().split())
l=[]
for _ in range(N):
    a,b = map(int,input().split())
    l.append((a,b))
l.sort()
L = collections.deque(l)
ans = 0
while M>0:
    a,b = L.popleft()
    if M>=b:
        ans += a*b
    else:
        ans +=a*M
    M-=b
print(ans)

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


drink.sort()

money=0
number=0
for i in range(n):
    if number+drink[i][1]<=m:
        money+=drink[i][0]*drink[i][1]
        number+=drink[i][1]
    elif m<number+drink[i][1]:
        money+=drink[i][0]*(m-number)
        number+=m-number
        break
    if m==number:
        break
print(money)

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

    return n,m,ab

def main(n,m,ab):
    ab2=sorted(ab)
    price=0
    bought=0
    for i in range(n):
        a,b=ab2[i]
        if(bought+b>=m):
            buy=m-bought
            price+=a*buy
            return price
        bought+=b
        price+=a*b

if __name__=='__main__':
    n,m,ab=readinput()
    ans=main(n,m,ab)
    print(ans)

Solution (Python):
N,M=map(int,input().split())
l=sorted(list(tuple(map(int,input().split()))for i in range(N)),key=lambda x:x[0])
c=0
ans=0
for v,k in l:
    ans+=min(k,M-c)*v
    c+=min(k,M-c)
    if c==M:
        print(ans);exit()