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):
from operator import itemgetter
A = []

def main():
    accum = 0
    cost = 0
    N, M = map(int, input().split())
    for i in range(N):
        A.append(list(map(int, input().split())))
    B = sorted(A, key = itemgetter(0))
    while accum < M:
         eB = B.pop(0)
         if accum + eB[1] > M:
             cost += eB[0] * (M - accum)
             accum = M
         else:
             accum += eB[1]
             cost += eB[0] * eB[1]
    print(cost)

main()

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

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

ab.sort()

sum = 0
num = m
for i in range(n):
	if(0 >= num):
		break
	sum += ab[i][0]*min(ab[i][1],num)
	num -= ab[i][1]

print(sum)

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











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

final = 0
sum_bottles = 0
while(M > sum_bottles):
    final += 1
    sum_bottles += AB[final-1][1]

cost = 0
sum_bottles = 0
for i in range(final):
    if i == final - 1:
        cost += AB[i][0] * (M - sum_bottles)
    else:
        cost += AB[i][0] * AB[i][1]
        sum_bottles += AB[i][1]

print(cost)

Solution (Python):


N, M = map(int, input().split())
AB = [[int(x) for x in input().split()] for n in range(N)]


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


cnt = 0 
prc = 0 
i = 0
while cnt < M:
    a, b = AB[i]
    if cnt+b <= M:
        cnt += b
        prc += a*b
    else:
        prc += a*(M-cnt)
        cnt = M
    i+=1

print(prc)

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

for A, B in lst:
    if M == 0:
        break
    for i in range(B):
        price += A
        M -= 1
        if M == 0:
            break

print(price)

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()
n = 0
ans = 0
for i in range(N):
    A,B = l[i]
    if n+B <= M:
        ans += A*B
        n += B
    else:
        ans += A*(M-n)
        n += M-n
    if n==M:
        break
print(ans)

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

money = 0

for j,k in li:
    money += j * min(k,m)
    m -= k
    if m <= 0:
        break

print(money)

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

money = 0
count = 0

while m > 0:
    if m > li[count][1]:
        money += li[count][0] * li[count][1]
        m -= li[count][1]
        count += 1
    else:
        money += li[count][0] * m
        m = 0
        count += 1

print(money)

Solution (Python):
N,M=map(int,input().split())
L=[]
for i in range(N) :
  A=list(map(int,input().split()))
  L.append(A)
L.sort()
P=0
for j,k in L :
  P+=j*min(k,M)
  M-=k
  if M<=0 :
    break
print(P)

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

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

AB_list=[]

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

AB_list = sorted(AB_list)
cost = 0
num = 0
for AB in AB_list:
    num = AB[1]
    if M > num:
        cost += AB[0]*num
        M -= num
    else:
        cost += AB[0]*M
        break

print(cost)

Solution (Python):
def main():

    N, M = map(int, input().split())
    data = [None] * N
    for n in range(N):
        data[n] = [int(x) for x in input().split()]

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

    m = 0
    y = 0
    for n in range(N):
        if m + data[n][1] > M:
            y += (M - m) * data[n][0]
            break
        else:
            y += data[n][1] * data[n][0]
            m += data[n][1]

    print(y)


main()

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

Solution (Python):
N, M = map(int,input().split())
A = []
B = []
ta = 0
tb = 0





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

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

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

Solution (Python):

"""
C - Energy Drink Collector
https://atcoder.jp/contests/abc121/tasks/abc121_c

"""
import sys


def solve(stores, M):
    total_price = 0
    for s in stores:
        if M <= s[1]:
            return total_price + (s[0] * M)
        total_price += (s[0] * s[1])
        M -= s[1]
    return -1


def main(args):
    N, M = map(int, input().split())
    stores = sorted([[int(i) for i in input().split()] for _ in range(N)])
    ans = solve(stores, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

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

Solution (Python):
from collections import defaultdict

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

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

prices = sorted(list(price_to_nums.keys()))

total = 0
left = M
for i in range(len(prices)):
    price = prices[i]
    c = min(price_to_nums[price], left)
    total += c * price
    left -= c
    if left <= 0:
        break

print(total)

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

ans = 0

while(M > 0):
    for j in range(N):
        ans += drink[j][0] * min(M, drink[j][1])
        if M >= drink[j][1]:
            M -= drink[j][1]        
        else:
            M = 0
print(ans)

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

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

Solution (Python):
n, m = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(n)))
c = sorted(zip(a, b))
cost = 0
rest = m
for a, b in c:
    if rest >= b:  
        cost += a * b
        rest -= b
    else:  
        cost += a * rest
        break
print(cost)

Solution (Python):
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N)))
C = sorted(zip(A, B))
ans = 0
m = M
for a, b in C:
    if m >= b:
        ans += a * b
        m -= b
    else:
        ans += a * m
        break
print(ans)

Solution (Python):
def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])])
    ans = 0
    for a, b in ab:
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, m, *ab = map(int, string.split())
    ans = 0
    for a, b in sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])]):
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, m, *ab = map(int, string.split())
    ans = 0
    for a, b in sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])]):
        ans += a * min(b, m)
        m -= b
        if m <= 0:
            break
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

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

Solution (Python):
def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])])
    ans = 0
    for a, b in ab:
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])], key=lambda x: x[0])
    ans = 0
    for a, b in ab:
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
import numpy as np
def solve(n, m, a, b):
    records = sorted(list(zip(a, b)), key=lambda _: _[0])
    cnt = 0
    res = 0
    for a_i, b_i in records:
        next = cnt + b_i
        if m <= next:
            c = m - cnt
            res += a_i * c
            break
        else:
            res += a_i * b_i
        cnt = next
    return res

n, m = map(int, input().split())
a, b = np.zeros(n, dtype=int), np.zeros(n, dtype=int)
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, m, a, b))

Solution (Python):
n,m=map(int,input().split())
dataset=sorted([tuple(map(int,input().split())) for i in range(n)])
ans=0
for data in dataset:
  if m==0:
    print(ans)
    exit()
  tmp=min(data[1],m)
  ans+=tmp*data[0]
  m-=tmp
print(ans)

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

for n in range(N):
    cost = AB[n][0]
    max_buy = AB[n][1]
    for mb in range(max_buy):
        min_pay += cost
        num_buy += 1
        if num_buy == M:
            print(min_pay)
            exit()

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

Solution (Python):
N, M = map(int, input().split())
ABs = [list(map(int, input().split())) for _ in range(N)]
ABs = sorted(ABs, key=lambda ab: ab[0])

m = 0
c = 0
for AB in ABs:
    a, b = AB
    for _ in range(b):
        m += a
        c += 1
        if c >= M:
            break
    else:
        continue
    break

print(m)

Solution (Python):
storeNum, target = map(int, input().split(' '))
stores = []

for i in range(storeNum):
    cost, mx = map(int, input().split(' '))
    stores.append((cost, mx))

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

totalCost = 0
totalCan = 0
for cost, cans in stores:
    totalCost += cost * cans
    totalCan += cans
    if target <= totalCan:
        totalCost -= (totalCan - target) * cost
        print(totalCost)
        break

Solution (Python):
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []
B_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict.setdefault(A, 0)
  num_dict[A] += B
  A_list.append(A)

A_list = list(set(A_list))
A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    break
    
print(all_pay)

Solution (Python):


import sys
input = sys.stdin.readline

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
for k in AB:
    if M > k[1]:
        M -= k[1]
        ans += k[0] * k[1]
    else:
        ans += k[0] * M
        break

print(ans)

Solution (Python):


import sys
input = sys.stdin.readline

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

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

k = 0
ans = 0
while True:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)

Solution (Python):


import sys
input = sys.stdin.readline

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

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

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

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

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)

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

from operator import itemgetter
N, M = map(int, input().split())
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    
l = list(zip(A, B))
l.sort(key=itemgetter(0))
ans = 0
judge = 0
flag = False
for i in range(N):
    for j in range(l[i][1]):
        ans += l[i][0]
        judge += 1
        if judge == M:
            flag = True
            break
    if flag:
        break

print(ans)

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

AB = sorted(AB)
price = 0
m = 0

for a, b in AB:
    if m + b < M:
        price = price + a * b
        m = m + b
    elif m + b >=M:
        price = price + a * (M - m)
        m = M
        break

print(price)

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])
buy = 0
money = 0
for i in range(N):
  if buy+ab_[i][1] > M:
    money += (M-buy)*ab_[i][0]
    break
  else:
    money += ab_[i][0]*ab_[i][1]
    buy += ab_[i][1]

print(money)

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

money = 0

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

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

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

S.sort()
m=0
while M>0:
    for i in range(N):
        if S[i][1]<=M:
            m+=S[i][0]*S[i][1]
            M-=S[i][1]
        else:
            m+=S[i][0]*M
            M=0
            break

print(m)

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

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

Solution (Python):
def main():
    n, m = map(int, input().split())
    ts = sorted(tuple(map(int, input().split())) for _ in range(n))
    res = 0
    i = 0
    while m > 0:
        b = min(ts[i][1], m)
        res += ts[i][0] * b
        m -= b
        i += 1
    print(res)


if __name__ == "__main__":
    main()

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

for info in l:
  a, b = info
  if m <= b:
    print(ans + m * a)
    break
  else:
    ans += a * b
    m -= b

Solution (Python):
import numpy as np
N, M = list(map(int, input().split()))
data = []
for i in range(N):
  data.append(list(map(int, input().split())))
data = np.asarray(data)
data = data[np.argsort(data[:, 0], axis=0)]

res = 0
for info in data:
  for i in range(info[1]):
    M -= 1
    res += info[0]
    if M==0:
      break
  if M==0:
    break
print(res)

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

AB=[]







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

"""
for i in range(N):
    print(AB[i][0],AB[i][1])
"""

AB.sort()
"""
for i in range(N):
    print(AB[i][0],AB[i][1])
"""    
ySum=0
dSum=0
for i in range(N):
    cnt=0
    while(cnt<AB[i][1]):
        if(dSum==M):
            break
        ySum=ySum+AB[i][0]
        cnt+=1
        dSum+=1
            
print(ySum)

Solution (Python):
n,m=map(int,input().split())
c=0;d={}
for _ in[0]*n:
 a,b=map(int,input().split())
 if not a in d.keys():
  d[a]=0
 d[a]+=b
for k in sorted(d.keys()):
 if d[k] < m:
  c+=k*d[k]
  m-=d[k]
 else:
  c+=k*m
  m=0
 if m == 0:break
print(c)

Solution (Python):
from operator import itemgetter

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

b.sort(key=itemgetter(0))


c=0 
d=0 
for i in range(N):
    c+=b[i][1]
    d+=b[i][0]*b[i][1]
    if c>M:
        d-=(c-M)*b[i][0]
        break
print(d)

Solution (Python):
N, M = map(int, input().split())
drink = []
for _ in range(N):
    drink.append(list(map(int, input().split())))
drink = sorted(drink)
money = 0
honsuu = 0
for i in range(N):
    if honsuu + drink[i][1] <= M:
        money += drink[i][0] * drink[i][1]
        honsuu += drink[i][1]
    else:
        money += drink[i][0] * (M-honsuu)
        break
print(money)

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

for j in range(n):
    shop = li[j]
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

Solution (Python):
from operator import itemgetter

n, m = map(int, input().split())
money = 0
li = [list(map(int, input().split())) for _ in range(n)]
li.sort(key=itemgetter(0))

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

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

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

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

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

while 0 < m:
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

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

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

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

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

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

A, B = zip(*sorted(zip(A, B)))
cost = 0
for i in range(N):
    if M > B[i]:
        cost += A[i] * B[i]
        M -= B[i]
    else:
        cost += A[i] * M
        break

print(cost)

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

A_B_list = []
for i in range(N):
    A_B = [int(i) for i in input().split()]
    A_B_list.append(A_B)

ans = 0
A_B_list = sorted(A_B_list)

for A_B in A_B_list:
    if M - A_B[-1] > 0:
        ans += A_B[0]*A_B[-1]
        M -= A_B[-1]
    else:
        ans += A_B[0]*M
        break

print(ans)

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

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

Solution (Python):
from operator import itemgetter
nm = input().split()
n = int(nm[0])
m = int(nm[1])
a_li = []
b_li = []
for i in range(n):
    ab_li = input().split()
    a_li.append(int(ab_li[0]))
    b_li.append(int(ab_li[1]))
ab_connected = sorted(zip(a_li, b_li), key=itemgetter(0))
a_li, b_li = zip(*ab_connected)
item_count = 0
price_count = 0
for i in range(n):
    if item_count < m:
        if b_li[i] <= (m - item_count):
            item_count += b_li[i]
            price_count += a_li[i] * b_li[i]
        else:
            item_needed = 0
            item_needed = m - item_count
            item_count += item_needed
            price_count += item_needed * a_li[i]
    elif item_count == m:
        break
    else:
        print("error")
print(price_count)

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

store = []

for i in range(n):
  price,stock = map(int,input().split())
  store.append([price,stock])

store.sort()

total_cost = 0
for i in range(n):
  if m > 0:
    buy = min([m,store[i][1]])
    total_cost += buy * store[i][0]
    m -= buy
  else:
    break

print(total_cost)

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

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

zan = m
money = 0
for shop in sorted(li_shop, key=lambda x: x[0]):
    if zan > shop[1]:
        
        buy = shop[1]
        money += shop[0] * buy
        zan = zan - buy
    else:
        buy = zan
        money += shop[0] * buy
        zan = 0
print(money)

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

money = 0

for a,b in AB:
    if M <= 0:
        break
    if M-b >= 0:
        money += a*b 
        M -=b 
    else:
        money += a*M
        M -=M

print(money)

Solution (Python):
N,M = (int(_) for _ in input().split())
shops = []
NumberOfEDWillBuy = []
for i in range(N):
    price,stock = (int(_) for _ in input().split())
    shops.append((price,stock))




NumberOfEDWanted = M
sortedShops = sorted(shops,key = lambda shop:shop[0])
for shop in sortedShops:
    if NumberOfEDWanted < shop[1]:
        NumberOfEDWillBuy.append(NumberOfEDWanted)
        NumberOfEDWanted = 0
    else:
        NumberOfEDWillBuy.append(shop[1])
        NumberOfEDWanted -= shop[1]
sum = 0
for i in range(len(NumberOfEDWillBuy)):
    sum += sortedShops[i][0]*NumberOfEDWillBuy[i]
print(sum)

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.sort()
cost = 0
num = 0
idx = 0
for i in range(N-1):
    if num + A[i][1] <= M:
        num += A[i][1]
        cost += A[i][0]*A[i][1]
        idx += 1
    else:
        break
num_left = M-num
cost += A[idx][0] * num_left
print(cost)

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

Solution (Python):
N, M = list(map(int, input().split()))
A, B = [], []
for _ in range(N):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)
  
C = sorted(zip(A,B), key=lambda x:x[0])

total=0
i=0
while M>0:
  a = C[i][0]
  b = C[i][1]
  if M<=b:
    total = total + a*M
    M = 0
  else:
    total = total + a*b
    M = M-b
  i+=1
print(total)

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

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

Solution (Python):
from operator import itemgetter

def key_func(n):
	return n[0]

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

list_price_and_energydrink = []

for i in range(N):
	A_i, B_i = map(int, input().split())
	list_shop_number_i = [A_i, B_i]
	list_price_and_energydrink.append(list_shop_number_i)

count_number_drink = 0
count_price_drink = 0

list_price_and_energydrink.sort(key=itemgetter(0))

while count_number_drink < M:
	list_minimum_i = list_price_and_energydrink[0]
	
	if count_number_drink + list_minimum_i[1] > M:
		count_price_drink += list_minimum_i[0] * (M - count_number_drink)
		count_number_drink = M
	else:
		count_number_drink += list_minimum_i[1]
		count_price_drink += list_minimum_i[0] * list_minimum_i[1]	
	
	list_price_and_energydrink.remove(list_minimum_i)

print(count_price_drink)

Solution (Python):
a = list(map(int, input().split())) 

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

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

botles = 0
sum_money = 0
for j in range(len(money_hon_list)):
    for k in range(money_hon_list[j][1]):
        if botles < int(a[1]):
            sum_money += money_hon_list[j][0]
            botles += 1
        else:
            break

print(sum_money)

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

X=[]

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

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

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

print(ans)

Solution (Python):
import io, sys, atexit, os

import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


def li ():
	return list (map (int, input ().split ()))


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


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


mm = 1000000007



def solve ():
	t = 1
	for it in range (t):
		n,m=num()
		x=[]
		for i in range(n):
			l,r=num()
			x.append((l,r))
		x.sort()
		cc=m
		cost=0
		for i in range(n):
			cost+=x[i][0]*min(cc,x[i][1])
			cc-=min(cc,x[i][1])
		print(cost)






if __name__ == "__main__":
	solve ()

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())
    
arr = [[0]*2 for i in range(N)]
for i in range(N):
    arr[i] = [A[i],B[i]]
    
arr = sorted(arr,key=lambda x:x[0])

count = 0 
money = 0 
i = 0
while count < M:
    if (count+arr[i][1]) >= (M):
        money += arr[i][0] * (M - count)
        break
    else:
        count += arr[i][1]
        money += arr[i][0] * arr[i][1]
    i += 1

print(money)

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

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

sortedData = sorted(data, key=lambda a: a[0])
cost = 0
tmpM = 0
for a, b in sortedData:
	if (m - tmpM) >= b:
		cost += a * b
		tmpM += b
	else:
		cost += a * (m-tmpM)
		break

print(cost)

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

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

costs = 0

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

print(costs)

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

Solution (Python):
n, m = map(lambda x:int(x), input().split())
a_list = []
b_list = []
for i in range(n):
    a, b = [int(i) for i in input().split()]
    a_list.append([i, a])
    b_list.append(b)

a_list.sort(key=lambda a: a[1], reverse=False)
count = 0
ans = 0
for i in range(n):
    index = a_list[i][0]
    if (count + b_list[index]) >= m:
        ans += (m - count) * a_list[i][1]
        break
    else:
        count += b_list[index]
        ans += a_list[i][1] * b_list[index]

print(ans)

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

Solution (Python):



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

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




SET=[[A[i],B[i]]for i in range(N)]

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


total=0
money=0
for i in range(len(SET)):
	for j in range(SET[i][1]):
		if(total>=M):
			print(money)
			exit()
		total+=1
		money+=SET[i][0]
		
print(money)

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

ans = 0
count = 0

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

Solution (Python):
import numpy as np
N,les=list(map(int,input().split()))
data=np.array([list(map(int,input().split())) for _ in range(N)])
cost=0

t=data[:,0]
for n in np.argsort(data[:,0]):
    if data[n][1]>les:
        cost+=les*data[n][0]
        break
    else:
        les-=data[n][1]
        cost+=data[n][0]*data[n][1]
print(cost)