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

Solution (Python):

import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 
a=nCast(input().split());

b=nCast(inputArr1(a[0]))


def bkey(n):
    return n[0]
 
def func():
    b.sort(key=bkey)
    sum=0
    count=0
    for idx in range(0,len(b)):

        if count+b[idx][1]<a[1]:
            count+=b[idx][1]
            sum+=b[idx][0]*b[idx][1]
        else:
            sum+=b[idx][0]*(a[1]-count)
            return sum
    return sum
    
print(func())

Solution (Python):
import numpy as np
N, M = map(int, input().split(' '))
A = []
B = []
for i in range(N):
    Ai, Bi = map(int, input().split(' '))
    A.append(Ai)
    B.append(Bi)
A, B = zip(*(sorted(zip(A, B))))
A = np.array(A)
B = np.array(B)
temp_B = 0
for i, num in enumerate(B):
    temp_B += num
    if(temp_B >= M):
        break
ans = 0
ans += sum(A[:i+1]*B[:i+1])
ans -= A[i] * (temp_B - M)
print(ans)

Solution (Python):
num_shops, target_drinks = map(int, input().split())
sell = {}

for _ in range(num_shops):
    a,b = map(int, input().split())

    try:
        sell[a] += b
    except:
        sell[a] = b

ans, bought = 0, 0

for price in sorted(sell):

    selling = sell[price]

    if bought + selling < target_drinks:
        ans += price * selling    
        bought += selling
    else:
        ans += price * (target_drinks - bought)
        break

print(ans)

Solution (Python):


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

sorted_AB = sorted(AB, key=lambda x: x[0])
remaining = M
value = 0
for a, b in sorted_AB:
    for i in range(b):
        remaining -= 1
        value += a
        if remaining <= 0:
            break
    else:
        continue
    break

print(value)

Solution (Python):
import sys
DBG = not True
n,m =      map(int, input().split())
c = []
for i in range(n):
  a,b = map(int, input().split())
  c.append([a,b])

c.sort(key=lambda x: x[0])
if DBG:
    print(n)
    print(m)
    print(c)
money = 0
drink = 0
for i in range(n):
    ai = c[i][0]
    bi = c[i][1]
    if DBG:
        print("i {} d {} m {}".format(i, drink,money))
        print("ai {} bi {}".format(ai, bi))
    if drink + bi >= m:
        print(money + ai*(m-drink))
        break
    else:
        drink += bi
        money += ai * bi

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

res = 0
for a,b in ab:
  if m <= b:
    res += a*m
    break
  res += a*b
  m -= b

print(res)

Solution (Python):



n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for _ in range(n)]

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



c=0
ans = 0
i=0
while(c<m):
    if m-c <= a[i][1]:
        ans += (m-c)*a[i][0]
        c += m-c
    else:
        ans += a[i][1]*a[i][0]
        c+=a[i][1]
    i+=1

print(ans)

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

Solution (Python):
n,m=[int(x) for x in input().split()]
ab=[]
for _ in [0]*n:
    ai,bi=[int(x) for x in input().split()]
    ab.append((ai,bi))
ans=0
ab=sorted(ab,key=lambda x :x[0])
for a,b in ab:
    if b>=m:
        ans+=m*a
        break
    else:
        ans+=a*b
        m-=b
print(ans)

Solution (Python):
N,M = map(int,input().split())
d = {}
for _ in range(N):
    a,b = map(int,input().split())
    if not a in d.keys():
        d[a] = b
    else:
        d[a] += b

cost = 0
for c in sorted(d.keys()):
    
    if M < d[c]:
        cost += c * M
        break
    else:
        cost += c * d[c]
        M -= d[c] 
print(cost)

Solution (Python):
from operator import itemgetter
n, m = [int(i) for i in input().split()]
A = []
for i in range(n):
    A.append([int(j) for j in input().split()])
A = sorted(A, key=itemgetter(0))
cur_drink = 0
cur_cost = 0
for i in range(m):
    if cur_drink < m:
        more_drink = min(m - cur_drink, A[i][1])
        cur_drink += more_drink
        cur_cost += more_drink * A[i][0]
    if cur_drink == m:
        break
print(cur_cost)

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

Solution (Python):
import numpy as np
N, M = map(int, input().split())
AB_list = np.zeros((N, 2))

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

if N==1:
    print(int(M*AB_list[0, 0]))

elif np.sum(AB_list[:, 1]) == M:
    tmpsum = 0
    for i in range(N):
        tmpsum += AB_list[i, 0] * AB_list[i, 1]
    print(int(tmpsum))

else:
    AB_list = AB_list[np.argsort(AB_list[:, 0])]
    i = 0
    money = 0
    while(AB_list[i, 1] <= M):
        money += AB_list[i,0] * AB_list[i, 1]
        M -= AB_list[i, 1]
        i += 1

    money += AB_list[i, 0] * M
    print(int(money))

Solution (Python):

import heapq

n, m = map(int, input().split())
ab = []
for _ in range(n):
    heapq.heappush(ab, tuple(map(int, input().split())))

ab = [heapq.heappop(ab) for i in range(len(ab))]
cost = 0
for a, b in ab:
    if b < m:
        cost += a * b
        m -= b
    else:
        cost += a * m
        break

print(cost)

Solution (Python):
from collections import namedtuple

Store = namedtuple('Store', 'a, b')

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

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

stores.sort(key=lambda s: s.a)

m = 0
cost = 0
for store in stores:
    for i in range(store.b):
        m += 1
        cost += store.a
        if m >= M:
            print(cost)
            exit(0)

Solution (Python):
import heapq

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

h = []
for i in range(N):
    A, B = map(int, input().split())
    heapq.heappush(h, (A, B))

count = 0
ans = 0
for i in range(N):
    A, B = heapq.heappop(h)
    if count + B >= M:
        ans += A * (M - count)
        break
    else:
        ans += A * B
        count += B
        
print(ans)

Solution (Python):

N, M = map(int, input().split())
ShopAB = []
sapp = ShopAB.append
for _ in range(N):
    sapp(list(map(int, input().split())))
ShopAB.sort()
cost = 0
i = 0
while M > 0: 
    price, maxquant = ShopAB[i][0], ShopAB[i][1]
    if M >= maxquant:
        cost += price * maxquant
        M -= maxquant
    else:
        cost += price * M
        M -= M
    i += 1
print(cost)

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

cur = 0
cur_v = 0
for a, b in shop:
    if cur + b > M:
        cur_v += (M - cur) * a
        break
    else:
        cur += b
        cur_v += a * b
print(cur_v)

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

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

ans=0

for a,b in A:
	if b<M:
		ans+=a*b
		M-=b
	else:
		ans+=a*M
		break
print ans

Solution (Python):


import sys
from collections import deque, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, m = LI()
    AB = [LI() for _ in range(n)]
    AB.sort()
    AB = deque(AB)

    cnt = 0
    res = 0
    while cnt < m:
        a, b = AB.popleft()
        cnt += b
        res += a * b

    if cnt > m:
        res -= a * (cnt - m)

    return res


print(main())

Solution (Python):
import random
 
def quick_sort(array):
    low_array = []
    high_array = []
    if len(array) <= 1:
        return array
    pivot = random.choice(array)[0]
    pivot_count = 0
    for a in range(len(array)):
        if pivot > array[a][0]:
            low_array.append(array[a])
        elif pivot < array[a][0]:
            high_array.append(array[a])
        else:
            pivot_count += 1
    print(pivot, low_array, high_array, pivot_count)
    low_array = quick_sort(low_array)
    high_array = quick_sort(high_array)
    return low_array + [pivot, ] * pivot_count + high_array
    
 
def main():
    list1=input().split(' ')
    n=int(list1[0])
    m=int(list1[1])
    biglist=[]
    for i in range(n):
        list=input().split(' ')
        biglist.append([int(list[0]), int(list[1])])
    
    array=[[5,1], [2,3], [3,4], [7,2], [6,6]]
    
    
    newlist=sorted(biglist)
    
    
    money=0
    jun=0
    while m>0:
        if newlist[jun][1]>=m:
            money+=m*newlist[jun][0]
            print(money)
            return
        else:
            money+=newlist[jun][0]*newlist[jun][1]
            
            m-=newlist[jun][1]
        jun+=1

main()

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

for i in range(n):
    ai, bi = list(map(int, input().split()))
    ab[i] = [ai, bi]
    
ab.sort(key = lambda x: x[0])
cnt = 0
yen = 0
i = 0
while True:
    if cnt + ab[i][1] >= m:
        yen += ab[i][0]*(m-cnt)
        
        break
    else:
        cnt += ab[i][1]
        yen += ab[i][1]*ab[i][0]
        
    i += 1

print(yen)

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

A.sort()
res = 0
ans = 0
for i in range(N):
    res += A[i][1]
    if M-res == 0:
        ans += A[i][0]*A[i][1]
        print(ans)
        break
    elif M-res > 0:
        ans += A[i][0]*A[i][1]
    else:
        res -= A[i][1]
        ans += A[i][0]*(M-res)
        print(ans)
        break

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

pair_list = []
for i in range(N):
    pair_list.append((A[i],B[i]))
pair_list.sort(key=lambda tup: tup[0],reverse=False)
sum_price = 0
sum_num = 0
for price, num in pair_list:
    if(sum_num + num >= M):
        sum_price += price * (M - sum_num)
        sum_num = N
        
        break
    else:
        sum_price += price * num
        sum_num += num
        

print(sum_price)

Solution (Python):
N, M = map(int, input().split())
A = []
B = []
ans = 0
for i in range(N):
    a, b = map(int, input().split())
    A.append([a, i])
    B.append(b)
A = sorted(A)
for i in range(len(A)):
    bn =  B[A[i][1]]
    if M > bn:
        M -= bn
        ans += A[i][0]  * bn
    else:
        ans += A[i][0] * M
        print(ans)
        exit()

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

NUM = 0
PRICE = 0
for idx in range(N):
  if list_[idx][1] < (M - NUM):
    PRICE += list_[idx][0] * list_[idx][1]
    NUM += list_[idx][1]
  else:
    PRICE += list_[idx][0] * (M - NUM)
    print(PRICE)
    exit()

Solution (Python):
n, m = map(int, input().split())
ab = {}
for i in range(n):
  a, b = map(int, input().split())
  if a in ab.keys():
  	ab[a] += b
  else:
    ab[a] = b

ab = sorted(ab.items(), key=lambda x: x[0])
res = 0
count = 0
for k, v in ab:
  if m - count >= v:
    count += v
    res += v * k
  else:
    res += k * (m - count)
    count += m - count
  
  if count == m:
    break
print(res)

Solution (Python):
import numpy as np
N,M = map(int,input().split())
A = np.empty(N,dtype=np.int64)
B = np.empty(N,dtype=np.int64)
for i in range(N):
    A[i],B[i] = map(np.int64, input().split())

order = A.argsort()
A = A[order]
B = B[order]
Y = 0
for i in range(N):
    if B[i] >= M:
        Y += A[i]*M
        break
    else:
        Y += A[i]*B[i]
        M -= B[i]

print(Y)

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

X.sort()

cnt = 0
cost = 0
for i in range(N):
    if cnt + X[i][1] < M:
        cnt += X[i][1]
        cost += X[i][1] * X[i][0]
    else:
        res = M - cnt
        cnt += X[i][1]
        cost += res * X[i][0]
        break

print(cost)

Solution (Python):

N, M = map(int, input().split())
shopList = [];

for i in range(N):
    Aap, Bap = map(int, input().split())
    listap = [Aap, Bap]
    shopList.append(listap);

cost = 0;
shopList.sort();

while(M>0):
    lowestPrice = shopList[0][0];
    if (shopList[0][1] >= M):
        cost += M*lowestPrice;
        M = 0;
    else:
        cost += shopList[0][1]*lowestPrice;
        M -= shopList[0][1];
        del shopList[0];

print(cost);

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

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
N, M = map(int, input().split())
A = [list(map(int,input().split())) for i in range(N)]
A.sort()
hon_li = [a[0] for a in A]
hon = 0
pre_hon = 0
turn = 0
for i in range(N):
    pre_hon = hon
    hon += A[i][1]
    if hon >= M:
        turn = i
        break
li = [A[k][0]*A[k][1] for k in range(turn)]
amari = A[turn][0] * (M - pre_hon)
ans = sum(li) + amari
print(ans)

Solution (Python):
N, M = list(map(int, input().split()))
A = list()
B = list()
for i in range(0, N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
zipped = zip(A, B)
zipped_sorted = sorted(zipped, key=lambda x:x[0])
A, B = zip(*zipped_sorted)
num = 0
total = 0
i = 0
while(True):
    if num + B[i] >= M:
        total += (M - num) * A[i]
        break
    num += B[i]
    total += A[i] * B[i]
    
    i += 1
print(total)

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

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

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

a.sort()

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

Solution (Python):
def main() -> None:
    N, M = map(int, input().split())
    l = [tuple(map(int, input().split())) for _ in range(N)]
    l.sort()
    yen = 0
    hon = M
    for v in l:
        if hon - v[1] > 0:
            hon -= v[1]
            yen += v[0] * v[1]
        elif hon - v[1] == 0:
            hon -= v[1]
            yen += v[0] * v[1]
            break
        else:
            yen += v[0] * hon
            break
    print(yen)


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split(" "))
list_ = []
for i in range(N):
  a, b = map(int, input().split(" "))
  list_.append([a, b])
  
list_.sort()  
total = 0
while M > 0:
  if M >= list_[0][1]:
    M -= list_[0][1]
    total += list_[0][0] * list_[0][1]
    del list_[0]
  else:
    total += list_[0][0] * M
    M = 0
print(total)

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

print(ans)

Solution (Python):
"""
C - Energy Drink Collector
"""


def solve():
    N, M = map(int, input().split())
    AB = [list(map(int, input().split())) for n in range(N)]
    AB.sort()
    ans = 0
    for a, b in AB:
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += a * M
            break
    print(ans)


if __name__ == '__main__':
    solve()

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


def readln():
    return list(map(int, read().split()))


N, M = readln()

A = []
B = []
data = {}
for _ in range(N):
    a, b = readln()
    A.append(a)
    B.append(b)
    data[a] = 0

for a, b in zip(A, B):
    data[a] += b

ans = 0
drink = 0
for k, v in sorted(data.items()):
    ans += k * v
    drink += v
    if drink > M:
        break
print(ans-k*(drink-M))

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])
ko=0
pri=0
i=0
while ko<=m:
  pri+=A[i][0]*A[i][1]
  ko+=A[i][1]
  i+=1
  if ko==m:
    print(pri)
    exit()
print(pri-(ko-m)*A[i-1][0])

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

print(money)

Solution (Python):
data = input().split()
N = int(data[0])
M = int(data[1])

AB = []

for lop in range(N):
    data = input().split()
    AB.append( [int(data[0]),int(data[1])] )


AB = sorted(AB)

money = 0
drink = 0
for lop in range(N):
    if AB[lop][1] + drink <= M:
        drink += AB[lop][1]
        money += AB[lop][0] * AB[lop][1]
    else:
        money += AB[lop][0] * (M - drink)
        break

print(money)

Solution (Python):

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
v = 0
for row in a:
    if m > row[1]:
        m -= row[1]
        v += row[0] * row[1]
    else:
        v += row[0] * m
        break
print(v)

Solution (Python):
n,m=map(int,input().split())
X=[[int(i) for i in input().split()] for j in range(n)]
X.sort(key=lambda X:X[0])
ans_sum=0
for i in range(n):
        for j in range(X[i][1]):
                m-=1
                ans_sum+=X[i][0]
                if m==0:
                        break
        if m==0:
                break
print(ans_sum)

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

Solution (Python):
N,M=map(int,input().split())
A_B=[list(map(int,input().split())) for _ in range(N)]
A_B.sort(key=lambda x:x[0])
ans=0
sum=0
for a_b in A_B:
    M-=a_b[1]
    if M<=0:
        ans+=(a_b[0]*a_b[1]+M*a_b[0])
        break
    else:
        ans+=a_b[0]*a_b[1]
print(ans)

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

for _ in range(n):
  a, b = (int(i) for i in input().split())
  tuple_list.append((a,b))

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

cost = 0
cans = 0
for t in tuple_sorted:
  if cans + t[1] < m:
    cost += t[0]*t[1]
    cans += t[1]
  else:
    buy_cans = m - cans
    cost += t[0] * buy_cans
    break

print(cost)

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

drinks = []

for _ in range(n):
    a, b = map(int, input().split())
    drinks += [[a, b]]

drinks.sort()

ans = 0

for drink in drinks:
    if m <= 0:
        break

    ans += min(m, drink[1]) * drink[0]
    m -= drink[1]

print(ans)

Solution (Python):
n, m = [int(elem) for elem in input().split()]
lst = []
for i in range(0, n):
    a, b = [int(elem) for elem in input().split()]
    lst.append((a, b))
sort_lst = sorted(lst)

cost = 0
j = 0
while m != 0:
    a, b = sort_lst[j]
    if m >= b:
        m -= b
        cost += a * b
        j += 1
    else:
        cost += a * m
        break
print(cost)

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

ab.sort(key=lambda a: a[0])
ans = 0
for i in ab:
    for a in range(i[1]):
        m -= 1
        if m < 0:
            break
        ans += i[0]
    
    if m < 0:
        break

print(ans)

Solution (Python):
import numpy as np
N, M = map(int,input().split(' '))

a = sorted([tuple(map(int,input().split(' '))) for i in range(N)])
def f(a, M):
    cost = 0 
    for i in a:
        if M > i[1]:
            cost += i[0]*i[1]
            M -= i[1]
            continue
        else :
            cost += i[0]*M
            return cost 

print(f(a, M))

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

i = 0
while(num_of_drinks < m):
    if num_of_drinks + a[i][1] < m:
      total += a[i][0] * a[i][1]
      num_of_drinks += a[i][1]
    else:
      total += a[i][0] * (m - num_of_drinks)
      num_of_drinks = m
    i += 1
    
print(total)

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

A = sorted(A)
money = 0
for n in range(N):
    if m > A[n][1]:
        m -= A[n][1]
        money += A[n][1] * A[n][0]
    elif m <= A[n][1]:
        money += m * A[n][0]
        break

print(money)

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

Solution (Python):
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(n)]
cost = 0
temp = 0
s_AB = sorted(AB)
for ab in s_AB:
    cost += ab[0]*ab[1]
    temp += ab[1]
    if(temp > m):
        cost -= ab[0]*(temp - m)
        break
    elif(temp == m):
        break
print(cost)

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

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])
x=0
ans = 0
for i in range(n):
  x = x + l[i][1]
  ans += l[i][0]*l[i][1]
  if x > m:
    ans = ans - l[i][0]*(x-m)
    break
print(ans)

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

print(money)

Solution (Python):
n, m = map(int, input().split())
data = []   
for i in range(n):
    a, b = map(int, input().split())
    data.append([a, b])
data.sort(key=lambda x: x[0])   
ans = 0
for p in data:
    ans += p[0] * min(m, p[1])
    m -= p[1]
    if m <= 0:
        break

print(ans)

Solution (Python):
import sys


def main():
    line = sys.stdin.readline()
    lst = [ int(s) for s in line.split()]
    n = lst[0]
    m = lst[1]

    shop_lst = []

    for i in range(n):
        line = sys.stdin.readline()
        lst = [ int(s) for s in line.split()]
        a = lst[0]
        b = lst[1]
        p = (a, b)

        shop_lst.append(p)

    sorted_lst = sorted(shop_lst, key=lambda p: p[0])

    total_cost = 0
    bottles = 0

    for a, b in sorted_lst:
        if bottles + b < m:
            
            total_cost += a * b
            bottles += b
            continue
        elif bottles + b == m:
            
            total_cost += a * b
            bottles += b
            break
        else:
            
            total_cost += a * (m - bottles)
            bottles += (m - bottles)
            break

    print(total_cost)

    return 0

if __name__ == '__main__':
    sys.exit(main())

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

b.sort()

su = 0
for i in range(len(b)):
    if b[i][1] >= m:
        su += b[i][0]*m
        m = 0
    else:
        su += b[i][0]*b[i][1]
        m -= b[i][1]

    if m == 0:
        break

print(su)

Solution (Python):
num_shop, num_want = map(int, input().split())

shops = []

for i in range(num_shop):
  price, hold = list(map(int, input().split()))
  shops.append([price, hold])

shops = sorted(shops, key = lambda x:x[0])
  
num_bought = 0
total_price = 0

for shop in shops:
  if shop[1] + num_bought >= num_want:
    total_price += (num_want - num_bought) * shop[0]
    break
  else:
    total_price += shop[0] * shop[1]
    num_bought += shop[1]

print(total_price)

Solution (Python):



N,M = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]
A.sort()
drink = 0
yen = 0
for i in A:
    if drink + i[1] >= M:
        yen += (M - drink) * i[0]
        print(yen)
        exit()
    else:
        yen += i[1] * i[0]
        drink += i[1]
    
print(A)

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

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

money = 0
need = M
for shop in shops:
    if shop[1] >= need:
        print(money + need * shop[0])
        exit(0)
    need -= shop[1]
    money += shop[0] * shop[1]

Solution (Python):
import numpy as np
N,M = list(map(int,input().split()))
A = []
X = 0
ans = 0
for i in range(N):
    A.append(list(map(int, input().split())))
B = sorted(A)
for i in range(N):
  if (X + B[i][1])<M:
    ans += B[i][0]*B[i][1]
    X += B[i][1]
  else:
    ans += B[i][0]*(M-X)
    break
print(ans)

Solution (Python):
n,m = map(int,input().split())
s = []
for i in range(n):
  s.append(list(map(int,input().split())))
s.sort()
total,count = 0,0
for j in range(n):
  for k in range(s[j][1]):
    total += s[j][0]
    count += 1
    if count == m:
      break
  if count == m:
    break

print(total)

Solution (Python):
N, M = map(int, input().split())
a = [[0*2]]*N
ans = 0
for i in range(N):
    a[i] = list(map(int, input().split()))

a.sort()
i = 0

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


print(ans)

Solution (Python):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for n in range(N)]
AB=sorted(AB)
money=0
n=0
D=0
while D<M:
    money+=AB[n][0]*AB[n][1]
    D+=AB[n][1]
    n+=1
money-=AB[n-1][0]*AB[n-1][1]
D-=AB[n-1][1]
print(money+AB[n-1][0]*(M-D))

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

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

money = 0
amount = 0
for a, b in data:
  amount += b
  money += a *b
  excess = (amount - M)
  if excess >= 0:
    money -= a * excess
    break

print(money)

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

Store_List=[]
for i in range(n):
    ai,bi=map(int,input().split())
    Store_List.append([ai,bi])


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


have=0
money=0
mise_index=0
while True:
    
    if have + Store_List[mise_index][1] < m:
       have+=Store_List[mise_index][1]
       money+=Store_List[mise_index][0]*Store_List[mise_index][1]
       mise_index+=1
    else:
        money+=Store_List[mise_index][0]*(m-have)
        break

print(money)

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

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

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

drinks.sort()
count = 0
cost = 0
for idx, drink in enumerate(drinks):
    count += drink[1]
    cost += drink[0]*drink[1]
    if count >= M:
        break

cost -= drinks[idx][0] * (count - M)
print(cost)

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

yen = 0
num = 0

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

Solution (Python):
N, M = map(int, input().split())
C = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
D = 0
E = 0
for i in range(N):
    if E + C[i][1] >= M:
        D += C[i][0]*(M - E)
        break
    D += C[i][0]*C[i][1]
    E += C[i][1]
print(D)

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

L = sorted(L)

res = 0
tmp = a[1]
for i in range(a[0]):
    if L[i][1] < tmp:
        res = res + L[i][0] * L[i][1]
        tmp = tmp - L[i][1]
    elif L[i][1] == tmp:
        res = res + L[i][0] * L[i][1]
        break
    else:
        res = res + L[i][0] * tmp
        break

print(res)

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

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