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

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

Solution (Python):
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split()))
                 for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)

Solution (Python):
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)

Solution (Python):
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split()))
                 for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)

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

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

num=0
money=0
for i in range(n):
    num+=x[i][1]
    money+=x[i][1]*x[i][0]
    if num>m:
        money=money-(num-m)*x[i][0]
        break
print(money)

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

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

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

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

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

AB_list = []
for i in range(N):
    AB = list(map(int, input().split()))
    AB_list.append(AB)
    
AB_list = sorted(AB_list, key=lambda x: x[0])

sum_drink = 0
sum_money = 0
num = 0
while True:
    if sum_drink + AB_list[num][1] <= M:
        sum_drink += AB_list[num][1]
        sum_money += AB_list[num][0] * AB_list[num][1]
        num += 1
        if num == N:
            break
    else:
        tmp_drink = M - sum_drink
        sum_money += AB_list[num][0] * tmp_drink
        break

print(sum_money)

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

AB.sort()
ret = 0
for A, B in AB :
    if B <= M :
        ret += A * B
        M -= B
    else :
        ret += A * M
        break
        
print(ret)

Solution (Python):
n,m=map(int,input().split())
info=[]
for i in range(n):
    cost,maxbuy=map(int,input().split())
    info.append([cost,maxbuy])
info2=sorted(info) 
total=0
num=0
i=0
while num<=m:
    if num+info2[i][1]>=m:
        total+=(m-num)*info2[i][0]
        break
    num+=info2[i][1]
    total+=info2[i][0]*info2[i][1]
    i+=1
print(total)

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

shop.sort()

drink=0
cost=0

for s in shop:
    if drink+s[1]>=M:
        cost+=s[0]*(M-drink)
        break
    drink+=s[1]
    cost+=s[0]*s[1]

print(cost)

Solution (Python):
if __name__ == '__main__':
    N, M = [int(n) for n in input().split()]
    A = []
    for n in range(N):
        A.append([int(n) for n in input().split()])

    vals = sorted(A, key=lambda x: x[0])
    ret = 0
    for v in vals:
        if v[1] < M:
            M -= v[1]
            ret += v[0] * v[1]
        else:
            print(ret + v[0] * M)
            exit()

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])
answer = 0 
current_amount = 0

for aabb in ab:
  if aabb[1] >= m - current_amount:
    answer += aabb[0]*(m-current_amount)
    print(answer)
    break
  else:
    answer += aabb[0]*aabb[1]
    current_amount += aabb[1]

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

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

Solution (Python):
import sys
N,M = map(int,input().split())
AB = []
s = 0
ans = 0
for i in range (0,N):
  A,B = map(int,input().split())
  AB.append([A,B])
AB.sort()

for i in range (0,N):
  if s + AB[i][1] >= M:
    ans = ans + (M - s) * AB[i][0]
    print(ans)
    sys.exit()
  s = s + AB[i][1]
  ans = ans + AB[i][0] * AB[i][1]

Solution (Python):
import heapq
h = []

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

for i in range(N):
  heapq.heappush(h, tuple(map(int, input().split())))

num = 0
result = 0

while(num < M):
  a, b = heapq.heappop(h)
  buyNum = min(b, M - num)
  num += buyNum
  result += buyNum * a
  
print(result)

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)
i=0
amount=0
cost=0
while True:
  if amount+AB[i][1]<m:
    amount+=AB[i][1]
    cost+=AB[i][0]*AB[i][1]
    i+=1
  else:
    cost+=(m-amount)*AB[i][0]
    print(cost)
    break

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


value = 0
hold = 0
while hold != M:
    if drink[0][1] == 0:
        drink.pop(0)
    value += drink[0][0]
    hold += 1
    drink[0][1] -= 1
print(value)

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


ab.sort()

cost = 0
bought = 0
for a, b in ab:
  buy = min(b, m - bought)
  cost += a * buy
  bought += buy
  if bought >= m:
    break

print(cost)

Solution (Python):
def main():
    n , m = map(int, input().split(' '))
    df = [list(map(int, input().split(' '))) for _ in range(n)]
    df.sort()
    result = 0
    counter = 0
    i = 0
    while counter < m:
        result += min(m-counter, df[i][1])*df[i][0]
        counter += df[i][1]
        i += 1
    print(result)
if __name__ == '__main__':
    main()

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

Solution (Python):
N,M = map(int,raw_input().split())
AB = [0]*N
for i in range(0,N):
  AB[i] = map(int,raw_input().split())
AB = sorted(AB,key=lambda x: x[0])
con = 0
ans = 0

for i in range(0,N):
  for j in range(0,AB[i][1]):
    con = con + 1
    ans = ans + AB[i][0]
    if con == M:
      break
  else:
    continue
  break
print ans

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

Solution (Python):
from operator import itemgetter

N, M = map(int, input().split())
A = []
B = []

for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


AB = zip(A,B)
AB = sorted(AB, key=itemgetter(0))

n_rest_drink = M
idx = 0
spent_money = 0

while n_rest_drink > 0:
    n_purchase = min(n_rest_drink, AB[idx][1])
    spent_money += AB[idx][0] * n_purchase
    n_rest_drink -= n_purchase
    idx += 1

print(spent_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])

i=0
cnt=0
money=0
while(i<len(ab)):
    if cnt + ab[i][1]>m:
        money+=(m-cnt)*ab[i][0]
        cnt=m
        break
    else:
        cnt+=ab[i][1]
        money+=ab[i][0]*ab[i][1]
    i+=1
print(money)

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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort()
    t = 0
    for a, b in ab:
        cnt = min(b, m)
        m -= cnt
        t += (cnt * a)
    print(t)


if __name__ == '__main__':
    slove()

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

lis.sort(key=lambda x:x[0])
num = 0
ans = 0
for i in range(N):
    if lis[i][1]<M-num:
        num += lis[i][1]
        ans += lis[i][0]*lis[i][1]
    else:
        ans += lis[i][0]*(M-num)
        break
print(ans)

Solution (Python):
from collections import deque

n,m = map(int,input().split())
stores = []
for _ in range(n):
    a,b = map(int,input().split())
    stores.append((a,b))
stores.sort()
stores = deque(stores)

count = m
ans = 0
while count != 0:
    a,b = stores.popleft()
    quantity = min(count,b)
    ans += a*quantity
    count -= quantity
print(ans)

Solution (Python):
N,M=map(int,input().split())
Xa={}
ans=0
for i in range(N):
    V,S=map(int,input().split())
    if V in Xa :
        Xa[V] += S
    else :
        Xa[V]=S
Xb=sorted(Xa.items())
for i in range (len(Xb)) :
    M -= Xb[i][1]
    ans += Xb[i][0]*Xb[i][1]
    if M <= 0 :
        ans -= abs(M)*Xb[i][0]
        break
 
print(ans)

Solution (Python):
import heapq
N,M = map(int,input().split())
AB = []
for _ in range(N):
  A,B = map(int,input().split())
  heapq.heappush(AB, [A,B])
  
num = 0
ans = 0
while num < M:
  A,B = heapq.heappop(AB)
  if num + B <= M:
    ans += A*B
    num += B
  else:
    ans += A*(M-num)
    num += M-num
print(ans)

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

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

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

nokori = M
price = 0

for j in AB_2:
  if nokori <= j[1]:
    price += j[0] * nokori
    break
  else:
    price += j[0] * j[1]
    nokori -= j[1]
  
print(price)

Solution (Python):
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    drinks = [tuple(map(int, input().split())) for _ in range(N)]
    drinks.sort()
    bought_cnt = 0
    cur_idx = 0
    ans = 0
    while bought_cnt < M:
        price,cnt = drinks[cur_idx]
        if M-bought_cnt >= cnt:
            bought_cnt += cnt
            ans += cnt*price
        else:
            ans += (M-bought_cnt)*price
            break
        cur_idx += 1
    print(ans)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
n, m = map(int, input().split())
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)

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

Solution (Python):
from operator import itemgetter
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key = itemgetter(0))

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

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

ans = 0
for price, amount in d:
    if M <= 0:
        break
    k = amount if amount < M else M
    ans += price * k
    M -= k

print(ans)

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

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

cost = 0

for i in range(n):
    value = drink[i][0]
    stock = drink[i][1]
    if m >= stock:
        cost += value*stock
        m -= stock
    else:
        cost += value*m
        m = 0
    if m == 0:
        break

print(cost)

Solution (Python):
import sys

s = input().split(" ")
n = int(s[0])
m = int(s[1])
a = []
for i in range(n):
	s = input().split(" ")
	a.append([int(s[0]), int(s[1])])

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

print(ans)

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

AB_s=sorted(AB)

ans=0
cnt=0
for a,b in AB_s:
    ans+=a*b
    cnt+=b
    if cnt>=M:
        ans-=a*(cnt-M)
        print(ans)
        exit()

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

h=0
k=0
i=0
while h+AB[i][1]<M:
    h+=AB[i][1]
    k+=AB[i][0]*AB[i][1]
    i+=1

k+=AB[i][0]*(M-h)

print(k)

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

AB = []

for _ in range(N):

    AB.append([int(x) for x in input().split()])

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

current_drinks = 0

current_buget = 0

for a, b in AB:

    num_buy = min(b, (M-current_drinks))

    current_drinks += num_buy

    current_buget += num_buy*a

    

    if current_drinks == M:

        break

print(current_buget)

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

ab.sort()

for i in ab:
    if m >= i[1]:
        res += i[0]* i[1]
        m -= i[1]
    else:
        res += i[0] * m
        m = 0
    if m == 0:
        break

print(res)

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

ans = 0
tmp = 0 
for r in sorted(AB):
    buy = min(M-tmp, r[1])
    tmp += buy
    ans += r[0] * buy
    if tmp == M:
        break
        
print(ans)

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

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

ab.sort()
ans = 0
num = 0
i = 0

while num < m:
    t = min(ab[i][1], m - num)
    ans += ab[i][0] * t
    num += t
    i += 1


print(ans)

Solution (Python):

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N,M = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(N)]
stores.sort()
total = 0
for store in stores:
    if store[1] < M:
        M -= store[1]
        total += store[0] * store[1]
    else:
        total += store[0] * M
        break
print(total)

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


def main():
    N, M = map(int, input().split())
    Q = []
    for _ in range(N):
        a, b = map(int, input().split())
        Q.append([a, b])
    heapq.heapify(Q)
    
    ans = 0
    cnt = 0
    while cnt<M:
        a, b = heapq.heappop(Q)
        ans += a * min(b, M-cnt)
        cnt += b

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    (N,M) = (int(i) for i in input().split())
    AB = [[int(j) for j in input().split()] for i in range(N)]
    AB.sort()
    cost=0
    for i in AB:
        if i[1] >= M:
            cost += M*i[0]
            print(cost)
            break
        else:
            cost += i[0]*i[1]
            M -= i[1]


if __name__ == "__main__":
    resolve()

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

for i in range(n):

    if count + ab[i][1] >= m:
        ans += ab[i][0] * (m - count)
        print(ans)
        exit()

    else:
        count += ab[i][1]
        ans += ab[i][0] * ab[i][1]

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

ans = 0
i = 0
while M:
  if L[i][1] < M:
    ans += L[i][0] * L[i][1]
    M -= L[i][1]
  else:
    ans += L[i][0] * M
    M = 0
  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()

sum = 0
ans = 0
i = 0
while sum < M:
    ans += AB[i][0]*min(AB[i][1],M-sum)
    sum = sum+AB[i][1]
    i +=1
print(ans)

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

Solution (Python):


















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

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

A = sorted(A)

count = 1
b = 0
cost = 0
for i in range(M):
    if i == M:
        break

    cost += A[b][0]

    if count == A[b][1]:
        count = 1
        b += 1
    else:
        count += 1


print(cost)

Solution (Python):
N, M = map(int, input().split())
drink, sumA, sumB = [], 0, 0
for _ in range(N):
    A,B = map(int, input().split())
    drink.append([A, B])
    sumA += A*B
    sumB += B 

if M == sumB:
    print(sumA)
elif M > sumB // 2:
    drink.sort(reverse=True)
    ans, exM = sumA, sumB - M
    while exM > 0:
        AB = drink.pop(0)
        b = min(exM, AB[1])
        ans -= b * AB[0]
        exM -= b
    print(ans)
else:
    drink.sort()
    ans = 0
    while M > 0:
        AB = drink.pop(0)
        b = min(M, AB[1])
        ans += b * AB[0]
        M -= b
    print(ans)

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

Solution (Python):
import heapq
N,M=map(int,input().split())
AB=[]
for i in range(N):
  a,b=map(int,input().split())
  heapq.heappush(AB,[a,b])
ans=0
bought=0
while bought!=M:
  lst=heapq.heappop(AB)
  A,B=lst[0],lst[1]
  if bought+B<=M:
    ans+=A*B
    bought+=B
  else:
    ans+=A*(M-bought)
    bought=M
print(ans)

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

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

for a, b in ab:
    num = min(b, m)
    total += a * num
    m -= num
    if m <= 0:
        break
print(total)

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

ans = 0

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

sai = sorted(range(len(a)), key=lambda k: a[k])

for i in range(n):
    bsai = min(m,b[sai[i]])
    m -= bsai
    ans += a[sai[i]]*bsai


print(ans)

Solution (Python):
import numpy as np

N, M=map(int, input().split())
AB=np.array([list(map(int, input().split())) for i in range(N)])

AB=AB[np.argsort(AB[:, 0])]

money=0
cans=0
shop=0
while cans<M:
  if cans+AB[shop, 1]<=M:
    money+=AB[shop, 0]*AB[shop, 1]
    cans+=AB[shop, 1]
  else:
    money+=AB[shop, 0]*(M-cans)
    cans+=AB[shop, 1]
    
  shop+=1
    
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])
 
y = 0
 
for i in range(len(AB)):
    p = min(M, AB[i][1])
    M -= p
    y += p*AB[i][0]
    if M == 0:
        break
 
print(y)

Solution (Python):
def main():
    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 range(n):
        for j in range(ab[i][1]):
            ans += ab[i][0]
            cnt += 1
            if cnt == m:
                print(ans)
                exit()


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

a = []

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

a.sort()

i = 0
ans = 0

while m > 0:
    if m > a[i][1]:
        ans += a[i][0] * a[i][1]
        m = m - a[i][1]
        i += 1
    else:
        ans += a[i][0] * m
        print(ans)
        sys.exit()

Solution (Python):

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

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

total_money = 0

for i in range(len(AB)):
    buy_cnt = min(M, AB[i][1])
    M -= buy_cnt
    total_money += buy_cnt*AB[i][0]
    if M == 0:
        break

print(total_money)

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

List.sort()
money = 0
d = 0
for i in range(N):
    if d >= M:
        break
    elif d+List[i][1] <= M:
        d += List[i][1]
        money += List[i][0]*List[i][1]
    elif d+List[i][1] > M:
        money += (M-d)*List[i][0]
        d = M

print(money)

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

Solution (Python):
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
li.sort()
i=0
goukei=0
goukeiM=0
while goukei<m:
  if li[i][1]+goukei<=m:
    goukei+=li[i][1]
    goukeiM+=(li[i][1])*(li[i][0])
    i+=1
  else:
    goukeiM+=(m-goukei)*(li[i][0])
    goukei=m
print(goukeiM)

Solution (Python):
N,M=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(N)]
B=sorted(A)
s=0
m=0
i=0
while s<M:
  if B[i][1]>0:
    m+=B[i][0]
    B[i][1]-=1
    s+=1
  else:
    i+=1
print(m)

Solution (Python):
import sys
from collections import *
from heapq import *
from fractions import gcd

sys.setrecursionlimit(10**6)

N, M = map(int, input().split(' '))
A = [0]*N

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

res = 0
for a in sorted(A):
    if(a[1] < M):
        M -= a[1]
        res += a[0] * a[1]
    else:
        res += a[0] * M
        M = 0
    if(M == 0):
        break
print(res)

exit()

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

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


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 (yen, num) in AB:
    if num <= M:
        ans += (yen * num)
        M -= num
    else:
        ans += (yen * M)
        print(ans)
        exit()

print(ans)

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

Solution (Python):
n,m = map(int, input().split())
d = {}
ans = 0
for _ in range(n):
  a,b = map(int, input().split())
  if a in d:
    d[a] += b
  else:
    d[a] = b

d = sorted(d.items(), key= lambda x: x[0])

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

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

print(cost)

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

AB.sort()
ans,cnt=0,0
for a,b in AB:
  for i in range(b):
    ans+=a
    cnt+=1
    if cnt>=m:
      print(ans)
      exit()

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

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

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

Solution (Python):
a = 0
l = []
f = 0
N, M = map(int, input().split())
for i in range(N):
    A, B = map(int, input().split())
    l.append([A, B])
l_sorted = sorted(l, key=lambda x: x[0])
while True:
    if l_sorted[f][1] < M:
        a += l_sorted[f][1] * l_sorted[f][0]
        M -= l_sorted[f][1]
        f += 1
    else:
        a += M * l_sorted[f][0]
        break
print(a)

Solution (Python):


N,M=map(int,input().split())
l=[[-1]*2 for i in range(N)]

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

l.sort()
sum=0
i=0
while M>0:
    num=min(M,l[i][1])
    sum+=num*l[i][0]
    M-=num
    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())))
cost = 0
count = 0
A.sort(key = lambda x:x[0])
for i in range(n):
  if count == m:
    break
  elif count + A[i][1] <= m:
    cost += A[i][1] * A[i][0]
    count += A[i][1]
  else:
    while count < m:
      cost += A[i][0]
      count += 1
print(cost)

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


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

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

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

res = M
n = 0
cnt = 0


while(AB[n][1] < res):
    cnt += AB[n][0] * AB[n][1]
    res -= AB[n][1]
    n += 1

cnt += res * AB[n][0]

print(cnt)

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

num=0
pay=0
for a,b in A:
	if num+b>=M:
		pay+=(M-num)*a
		break
	else:
		pay+=a*b
		num+=b

print(pay)

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

l = [[int(i) for i in input().split()] for _ in range(n)]

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


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

Solution (Python):
import sys
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(0,N):
  A[i],B[i]=map(int,input().split())
index=sorted(range(len(A)), key=lambda k: A[k])
cost=0
get=0
for i in index:
  if get+B[i]<M:
    get += B[i]
    cost += A[i]*B[i]
  else:
    cost += A[i]*(M-get)
    print(cost)
    sys.exit()