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())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if pm > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]

Solution (Python):
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
b = sorted(a)
pm = s = 0
m_minus_1 = m - 1
for item in b:
    tmp = pm + item[1]
    if tmp > m_minus_1:
        print(s + item[0] * (m - pm))
        break
    else:
        pm = tmp
        s += item[0] * item[1]

Solution (Python):
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    tmp = pm + item[1]
    if tmp > m_minus_1:
        print(s + item[0] * (m - pm))
        break
    else:
        pm = tmp
        s += item[0] * item[1]

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

Solution (Python):
from operator import itemgetter

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

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

A.sort(key=itemgetter(0))

num = 0
sum = 0

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

print(sum)

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

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

Solution (Python):
N,M = map(int,input().split())
number = M
answer = 0
ABlist = []

for x in range(0,N):
    A,B = map(int,input().split())
    ABlist.append([A,B])

ABlist.sort()

for x in ABlist:
    if x[1] >= number:
        answer += x[0] * number
        break
    else:
        answer += x[0] * x[1]
        number -= x[1]

print(answer)

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

sorted_ab = sorted(ab_list)

count = 0
current_price = 0
flag = False
for sab in sorted_ab :
    if count + sab[1] <= m :
        count += sab[1]
        current_price += sab[0] * sab[1]
    else :
        for i in range(sab[1]):
            if count == m :
                flag = True
                break
            count += 1
            current_price += sab[0]
    
    if flag == True:
        break
print(current_price)

Solution (Python):

import sys
import heapq

def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    l = [(A[i],B[i]) for i in range(N)]
    heapq.heapify(l)
    cost = 0
    while True:
        next = heapq.heappop(l)
        buyCount = min(M,next[1])
        cost += buyCount * next[0]
        M-= buyCount
        if M == 0:
            break
    print(cost)
    return



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):
from operator import itemgetter

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = sorted(drinklist, key=itemgetter(0))
sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

Solution (Python):
N, M = map(int, input().split())
a = []
for i in range(N):
	a.append(list(map(int, input().split())))
x = sorted(a)
cost = 0
k = 0
while x[k][1] < M:
	cost = cost +x[k][0] * x[k][1]
	M = M - x[k][1]
	k = k + 1
cost = cost + x[k][0] * M
print(cost)

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

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

AB.sort()
cost = 0
for i in range(N):
    M -= AB[i][1]
    cost += AB[i][1]*AB[i][0]
    if M<=0:
        store_num = i
        break
if M<0:
    m = abs(M)
    cost -= m*AB[store_num][0]
print(cost)

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

shops = []
class Shop:
    def __init__(self,a,b):
        self.a = a
        self.b = b
    def __lt__(self, other):
        return self.a < other.a

for _ in [0]*N:
    a, b = map(int, input().split())
    shop = Shop(a, b)
    shops.append(shop)

shops = sorted(shops)

m = 0
idx = 0
ans = 0
while m < M:
    buy = min(M-m, shops[idx].b)
    ans += buy * shops[idx].a
    m += buy
    idx += 1
print(ans)

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

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

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

Solution (Python):
from operator import itemgetter


N, M = map(int, input().split(" "))
AB = [list(map(int, input().split(" "))) for _ in range(N)]
AB = sorted(AB, key=itemgetter(0))

now = 0
ans = 0
for a, b in AB:
    ans += a * min(M-now, b)
    now += min(M-now, b)
    if now == M:
        break
print(ans)

Solution (Python):
import numpy as np
n, m = list(map(int, input().split()))

price = np.zeros(n)
limit = np.zeros(n)

for i in range(n):
    a, b = list(map(int, input().split()))
    price[i] = a
    limit[i] = b

p = 0
for i in price.argsort():
    l = limit[i]
   

    if l < m:
        
        p += price[i] * l
        m-=l
    else:
        
        p += price[i] * m
        break
print(int(p))

Solution (Python):
n, m = map(int, input().strip().split(' '))
store = []
for i in range(n):
    a, b = map(int, input().strip().split(' '))
    store.append([a,b])
store.sort()
price = 0
kosuu = 0
for i in range(n):
    if kosuu + store[i][1] > m:
        price = price + store[i][0]*(m-kosuu)
        break
    else:
        price = price + store[i][0]*store[i][1]
        kosuu = kosuu + store[i][1]
print(price)

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

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

A.sort()
p = 0
v = 0
for a in A:
    p += a[1]
    v += a[0] * a[1]
    if p >= M:
        v -= a[0] * (p - M)
        print(v)
        exit()

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

drinks = sorted(drinks, key = lambda x: x[0])
ans = 0
for a, b in drinks:
    if b < m:
        ans += a*b
    elif b == m:
        ans += a*b
        break
    else:
        ans += a*m
        break
    m -= b
print(ans)

Solution (Python):
n, m = map(int, input().split())
c=[[0 for i in range(2)] for i in range (n)]
for i in range(n):
    c[i][0],c[i][1] = map(int, input().split())
c.sort()
price=0
i=0
while(m>0):
    if(m>c[i][1]):
        price+=c[i][0]*c[i][1]
        m-=c[i][1]
    else:
        price+=c[i][0]*m
        m=0
    i+=1
print(price)

Solution (Python):
n, m = map(int, input().split())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
c=[[0 for i in range(2)] for i in range (n)]
for i in range(n):
    a[i],b[i] = map(int, input().split())
for i in range(n):
    c[i][0]=a[i]
for i in range(n):
    c[i][1]=b[i]
c.sort()
price=0
i=0
while(m>0):
    if(m>c[i][1]):
        price+=c[i][0]*c[i][1]
        m-=c[i][1]
    else:
        price+=c[i][0]*m
        m=0
    i+=1
print(price)

Solution (Python):

from operator import itemgetter
    
n, m = map(int, input().split())

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

price = 0
count = 0

for j in range(n):
    if count == m:
        break
    for k in range(int(stores[j][1])):
        if count < m:
            price += int(stores[j][0])
            count += 1
        else:
            break

print(price)

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

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

remain = M
price = 0
for a,b in shops:
  if b > remain:
    price += remain*a
    remain = 0
  else:
    price += a*b
    remain -= b
  if remain == 0:
  	break
print(price)

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


l = [None] * N

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

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

p = 0
m = 0

for a, b in l:
    p += a * b
    m += b
    if m >= M:
        p -= (m - M) * a
        break
print(p)

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

nap = []

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

nap.sort()


cost = 0
for i in range(N):
    if M == 0:
        break
    for j in range(nap[i][1]):
        cost += nap[i][0]
        M -= 1
        if M == 0:
            break
    
    

print(cost)

Solution (Python):
from operator import itemgetter

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

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

AB.sort(key=itemgetter(0, 1))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    money += A*B
    ct += B
    if ct >= M:
        money -= (ct - M)*A
        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(key=lambda x: (x[0], x[1]))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    money += A*B
    ct += B
    if ct >= M:
        money -= (ct - M)*A
        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(key=lambda x: (x[0], x[1]))

ct = 0
money = 0
for i in AB:
    A, B = i[0], i[1]
    for i in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)

Solution (Python):
n,m=[int(i) for i in input().split(' ')]
class P:
  def __init__(self, a, b):
    self.a = a
    self.b = b

p = []
for i in range(n):
  a,b=[int(i) for i in input().split(' ')]
  p.append(P(a, b))

  
mon = 0
p.sort(key=lambda x: x.a)
for e in p:
  if m <= e.b:
    mon += e.a * m
    m = 0
  else:
    m -= e.b
    mon += e.a * e.b

print(mon)

Solution (Python):
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
m=0
c=0
for i,x in enumerate(AB):
    m += x[1]
    c += x[0]*x[1]
    if m >= M:
        c -= (m-M)*x[0]
        print(c)
        exit()

Solution (Python):
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
m=0
c=0
for i,x in enumerate(AB):
    m += x[1]
    c += x[0]*x[1]
    if m >= M:
        c -= (m-M)*x[0]
        print(c)
        exit()

Solution (Python):
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x:x[0])
m=0
c=0
for i,x in enumerate(AB):
    m += x[1]
    c += x[0]*x[1]
    if m >= M:
        c -= (m-M)*x[0]
        print(c)
        exit()

Solution (Python):
n, m = [int(i) for i in input().split()]
dat = [[int(i) for i in input().split()] for i in range(n)]
dat.sort()
sum = 0
_m = 0
for i in dat:
    if _m + i[1] >= m:
        print(sum + i[0]*(m - _m))
        break
    _m += i[1]
    sum += i[0] * i[1]

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

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

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

Solution (Python):
import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])
 
a.sort(key=lambda x:x[0])
 
cost=0
shop=0
for j in range(M):
  if a[shop][1]==0:
    shop+=1
  a[shop][1]-=1
  cost+=a[shop][0]
print(cost)

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

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

Solution (Python):
N, M = map(int, input().split())
shops = [[int(i) for i in input().split()] for i in range(N)]
from operator import itemgetter
shops = sorted(shops, key=itemgetter(0))

ans = 0
k = 0
while M > 0:
    if M >= shops[k][1]:
        ans += shops[k][0] * shops[k][1]
        M -= shops[k][1]
    elif M < shops[k][1]:
        ans += shops[k][0] * M
        M = 0
    k += 1
print(ans)

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


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

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

cost = 0
count = M
i = 0

while count > 0 :
    if count >= AB[i][1]:
        count -= AB[i][1]
        cost += AB[i][1]*AB[i][0]
        i += 1
    else:
        cost += AB[i][0]*count
        count == 0
        break
    
print(cost)

Solution (Python):
import numpy as np
n,m=map(int,input().split())
a=np.zeros(n)
b=np.zeros(n)
for i in range(n):
    a[i],b[i]=map(int,input().split())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    m-=b[x[i]]
    i+=1
print(int(ans))

Solution (Python):
import numpy as np
N, M = map(int, input().split())
AB = np.empty((N, 2), dtype=np.int64)
for n in range(N):
    AB[n, :] = list(map(int, input().split()))
AB = AB[AB[:, 0].argsort(), :]
n = 0
ans = 0
while M > 0:
    if M > AB[n, 1]:
        ans += AB[n, 0] * AB[n, 1]
        M -= AB[n, 1]
    else:
        ans += AB[n, 0] * M
        M = 0
    n += 1
print(ans)

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

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

cost = 0
count = M
i = 0
while count > 0:
    if count >= nums[i][1]:
        count -= nums[i][1]
        cost += nums[i][1] * nums[i][0]
        i += 1
    else:
        cost += nums[i][0] * count
        count == 0
        break

print(cost)

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

A = sorted(A, key=lambda x: x[0])
money = 0
i = 0
while M > 0 and i < len(A):
    if M >= A[i][1]:
        M -= A[i][1]
        money += A[i][1] * A[i][0]
        i += 1
    else:
        money += M * A[i][0]
        i += 1
        M -= M
print(money)

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

Solution (Python):
import sys
input = sys.stdin.readline
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

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

num_of_drink, total_fee = 0, 0
List = sorted(List, key=lambda x:x[0])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

Solution (Python):
from operator import itemgetter
N,M = map(int,input().split(' '))
tuple_drink = []

for i in range(N):
  tuple_drink.append(tuple(map(int,input().split(' '))))
tuple_drink.sort(key=itemgetter(0))

num_drink = 0

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

Solution (Python):


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


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


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

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: 
    cost += store[0] * remaining
    break
  else: 
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)

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 x: x[0])

ans = 0
num = 0
i = 0
while True:
    if num + ABs[i][1] >= M:
        ans += (M - num) * ABs[i][0]
        break
    ans += ABs[i][1] * ABs[i][0]
    num += ABs[i][1]
    i += 1

print(ans)

Solution (Python):
n, m = map(int, input().split())
a = []
s = 0
stock = {}
for i in range(n):
    yen, s = map(int, input().split())
    if yen in stock:
        stock[yen] += s
    else:
        stock[yen] = s
        a.append(yen)
a.sort()
ans = 0
for i in range(n):
    s = stock[a[i]]
    if s < m:
        m -= s
        ans += s * a[i]
    else:
        ans += m * a[i]
        break
print(ans)

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

Solution (Python):
import heapq


def solve(priority_queue, amount):
    need_price = 0

    while amount > 0:
        price, count = heapq.heappop(priority_queue)
        need_price += price * min(amount, count)
        amount -= count

    return need_price


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

    priority_queue = list()
    for _ in range(n):
        item = list(map(int, input().split()))
        heapq.heappush(priority_queue, item)

    ans = solve(priority_queue, m)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
import bisect

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

drinks.sort(key = lambda x: x[0])
prices = np.array([x[0] for x in drinks])
vols = np.array([x[1] for x in drinks])
cum_vols = np.cumsum(vols)
idx = bisect.bisect_left(cum_vols, m) 


l = 0 if idx == 0 else sum(vols[:idx])

vols[idx] = m - l
print(np.dot(vols[:(idx+1)], prices[:(idx+1)]))

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

total = 0
number = 0
index = 0
while (number + L[index][1]) < M:
    number += L[index][1]
    total += L[index][0] * L[index][1]
    index += 1
    
    
total += L[index][0] * (M - number)
print(total)

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


remain = M
total_pay = 0
cur = 0
while remain > 0:
    buy = min(shop_list[cur][1], remain)
    total_pay = total_pay + shop_list[cur][0] * buy
    remain = remain - buy
    cur = cur + 1

print(total_pay)

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 = sorted(AB, key=lambda a: a[0])
total = 0
total_count = 0
for i in range(N):
    if total_count + AB[i][1] >= M:
        total += (AB[i][0] * (M - total_count))
        break
    else:
        total_count += AB[i][1]
        total += (AB[i][0] * AB[i][1])
print(total)

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

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

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



num = 0
yen = 0
for n in range(N):
    if num+AB[n][1] >= M:
        yen += (M-num)*AB[n][0]
        print(yen)
        break
    else:
        num += AB[n][1]
        yen += AB[n][1]*AB[n][0]

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

sys.maxsize = 10000000000000000


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

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



num = 0
yen = 0
for n in range(N):
    if num+AB[n][1] >= M:
        yen += (M-num)*AB[n][0]
        print(yen)
        break
    else:
        num += AB[n][1]
        yen += AB[n][1]*AB[n][0]

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

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

Solution (Python):
n,m = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(n)])
res = 0
for a,b in AB:
    m -= b
    if m >= 0:
        res += a*b
    else:
        m += b
        res += a*m
        break
print(res)

Solution (Python):



n,m = map(int,input().split())
a = [0] * n
b = [0] * n
c = [[0,0] for i in range(n)]
for i in range(n):
    a[i],b[i] = map(int,input().split())
    c[i] = [a[i],b[i]]

c.sort()

drink = 0
price = 0

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

print(price)

Solution (Python):
n, m = (int(i) for i in input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = sorted(a)
cnt = 0
money = 0
while True:
	for x,y in b:
		cnt += y
		money += x * y
		if m < cnt:
			money -= (cnt - m)*x
			print(money)
			exit()

Solution (Python):
N, M = list(map(int, input().split()))
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
  A[i], B[i] = list(map(int, input().split()))
k = list(range(N))
k.sort(key=lambda x: A[x])
r = 0
c = 0
for i in k:
  if B[i]<M-c:
    r += B[i]*A[i]
    c += B[i]
  else:
    r += (M-c)*A[i]
    c += M-c
    break
print(r)

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

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

ss.sort()

m = 0
for a, b in ss:
    m += a * min(b, M)
    M -= b
    if M <= 0:
        break

print(m)

Solution (Python):
import numpy as np

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

tmp_list = [[int(i) for i in input().split()] for i in range(N)]
tmp_list = np.array(tmp_list)

tmp_list = tmp_list[np.argsort(tmp_list[:, 0])].T
A_list = tmp_list[0]
B_list = tmp_list[1]





residue = M
min_cache = 0
idx = 0

while(True):
    if B_list[idx] >= residue:
        ans = min_cache + A_list[idx] * residue
        break
    else:
        residue = residue - B_list[idx]
        
        min_cache = min_cache + A_list[idx] * B_list[idx]
        
        idx += 1
    
print(ans)

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

AB = list(zip(A, B))
AB.sort()
A, B = zip(*AB)

sum = 0
num = 0
for i in range(N):
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            num += 1
            sum += A[i]
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]

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

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

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

Solution (Python):
def is_int(s):
    try:
        i = int(s)
    except:
        return False
    return True

ARGS_COUNT = 2
stdin = input().split()

if (len(stdin) > ARGS_COUNT):
    print("Too many arguments.")
    exit()
elif (len(stdin) < ARGS_COUNT):
    print("Too few arguments.")
    exit()
elif (not is_int(stdin[0])):
    print("N is not a number.")
    exit()
elif (not is_int(stdin[1])):
    print("M is not a number.")
    exit()

N = int(stdin[0])
M = int(stdin[1])

if (N < 1 or N > 100000):
    print("Out of range at N.")
    exit()
elif (M < 1 or M > 100000):
    print("Out of range at M.")
    exit()

A = [[] for j in range(N)]

for i in range(0, N):
    stdin = input().split()

    if (len(stdin) > ARGS_COUNT):
        print("Too many arguments.")
        exit()
    elif (len(stdin) < ARGS_COUNT):
        print("Too few arguments.")
        exit()
    elif (not is_int(stdin[0])):
        print("A[%d] is not a number." % (i + 1))
        exit()
    elif (not is_int(stdin[1])):
        print("B[%d] is not a number." % (i + 1))
        exit()
    elif(int(stdin[0]) < 1 or int(stdin[0]) > 1000000000):
        print("Out of range at A[%d]." % (i + 1))
        exit()
    elif (int(stdin[1]) < 1 or int(stdin[1]) > 100000):
        print("Out of range at B[%d]." % (i + 1))
        exit()

    A[i].append(int(stdin[0]))
    A[i].append(int(stdin[1]))

Bsum = 0
for a in A:
    Bsum += a[1]

if (Bsum < M):
    print("Summed B are less than M.")
    exit()

stores = sorted(A)
charge = 0

for store in stores:
    if (M <= 0):
        break
    if (M - store[1] >= 0):
        charge += store[0] * store[1]
        M -= store[1]
    elif (M - store[1] < 0):
        charge += store[0] * M
        M = 0

print(charge)

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

for A, B in sorted(AB):
    if M >= B:
        cost += A*B
        M -= B
    else:
        cost += A*M
        break

print(cost)

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

for A, B in sorted(AB):
    if M >= B:
        cost += A*B
        M -= B
        if M == 0:
            break
    else:
        cost += A*M
        break

print(cost)

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

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

print(price)

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

ret = 0    
for x in sorted(lst):
    a, b = x[0], x[1]
    for y in range(b):
        M -= 1
        ret += a
        if  M == 0:
            print(ret)
            exit(0)

Solution (Python):
N,M = map(int, raw_input().split())
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, raw_input().split())
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for AB_ in AB:
    num = min(M, AB_[1])
    total += AB_[0]*num
    M -= num
print total

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

	total = 0
	rest = m
	for i in range(n):
		if p[i][1] > rest:
			total += p[i][0]*rest
			break
		rest -= p[i][1]
		total += p[i][0] * p[i][1]
	print(total)

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

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

cost = 0
drinks = 0
for a, b in ab:
    after = drinks + b
    if after > m:
        cost += (m - drinks) * a
        break
    cost += a * b
    drinks += b
print(cost)