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 = []

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

cnt = 0
money = 0

for i in range(N):
    if cnt + AB[i][1] < M:
        cnt += AB[i][1]
        money += AB[i][0]*AB[i][1]
    else:
        for j in range(AB[i][1]):
            money += AB[i][0]
            if cnt + j + 1 == M:
                break
        break

print(money)

Solution (Python):


import numpy as np

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

ablist=np.array([list(map(int,input().split())) for i in range(n)])


newablist=ablist[ablist[:,0].argsort(),:]
x=newablist


costcount=0
i=0

while i<n and x[i][1]<= m:
	m -= x[i][1]
	costcount += x[i][0]*x[i][1]
	i += 1

if i < n:
	costcount += m*x[i][0]


print(costcount)

Solution (Python):


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

lst = sorted(lst)

cost = 0

drink = 0

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

Solution (Python):

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

lst = sorted(lst)

cost = 0

drink = 0

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

Solution (Python):

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




AB = []
for i in range(N):
    AB.append(tuple(int(x) for x in input().split()))

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

Solution (Python):
n, m = [ int(v) for v in input().split() ]
shop_data = sorted([ tuple( int(v) for v in input().split() ) for i in range(n) ])


cost = 0
for i in shop_data:
	cost += ( i[0] * min(m,i[1]) )
	m -= min(m,i[1])

print(cost)

Solution (Python):
n,m=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(n)])
ans=0
for a,b in ab:
    ans+=a*min(b,m)
    m-=b
    if m<=0:
        break

print(ans)

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

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

Solution (Python):

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

ab.sort()

price = [0 for _ in range(m)]
ii=0

while m > 0:
    m -= ab[ii][1]
    if m >= 0:
        price[ii] = ab[ii][1] * ab[ii][0]
    else:
        price[ii] = abs(m+ab[ii][1]) * ab[ii][0]
    ii += 1
        
print(sum(price))

Solution (Python):


N,M=map(int, input().split())
A=[]
B=[]
C=[]
count=0
index=0
remain=0
total=0
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)


import numpy as np
A=np.array(A)
B=np.array(B)
C=A.argsort()

for j in range(len(C)):
    if count<=M:
        count=count+B[C[j]]
        index+=1
    else:
        break
remain= count- M

for k in range(index):
    total=total+A[C[k]]*B[C[k]]
else:
    print(total-remain*A[C[k]])

Solution (Python):
N,M = map(int,input().split())
ABlist = [tuple(map(int,input().split())) for _ in range(N)]
ABlist.sort()
money = 0
for AB in ABlist:
    maz_num = AB[1]
    maz_pri = AB[0]
    add_m = maz_pri*maz_num
    if M > 0:
        money += add_m
        M -= maz_num
    if M == 0:
        break
    if M < 0:
        while M!=0:
            money -= maz_pri
            M += 1
        break

print(money)

Solution (Python):
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

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

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Solution (Python):
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

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

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

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

Solution (Python):

import sys
input = sys.stdin.readline

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

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

price=0
num=0
for i in range(N):
    if num+A[i][1]<M:
        price+=A[i][0]*A[i][1]
        num+=A[i][1]
    elif num<M and num+A[i][1]>=M:
        price+=A[i][0]*(M-num)
        break
    else:
        break
print(price)

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

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)

Solution (Python):
import sys


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
cnt = 0
for i, (Ai, Bi) in enumerate(AB):
    if cnt + Bi >= M:
        ans += Ai * (M - cnt)
        break
    else:
        cnt += Bi
        ans += Ai * Bi

print(ans)

Solution (Python):



import sys

input = sys.stdin.readline

def main():
    _, m = [int(e) for e in input().split()]

    N = []
    for l in sys.stdin:
        N.append([int(e) for e in l.strip().split()])
    N.sort(key=lambda x: x[0])
    total = 0
    for l in N:
        if m <= l[1]:
            total += l[0] * m
            m = 0
        else:
            m -= l[1]
            total += l[0] * l[1]
        if m == 0:
            break
    print(total)

main()

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

count = 0
buy = 0
for a, b in ab:
    for i in range(b):
        buy += a
        count += 1

        if count >= m:
            print(buy)
            exit()

Solution (Python):
def intinput():
    return map(int,input().split())

n,m=intinput()
a = [[0,0] for _ in range(n)]
for i in range(n):
    a[i] = list(intinput())
a.sort()
i=0
f=0
while m>0:
    if m>=a[i][1]:
        m -= a[i][1]
        f += a[i][1]*a[i][0]
    else:
        f += a[i][0]*m
        m=0
    i+=1
print(f)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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

    ans = 0
    now = 0
    for a, b in v:
        buy = min(M - now, b)
        ans += buy * a
        now += buy

    print(ans)


if __name__ == '__main__':
    main()

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

total_pay = 0
for ab in AB:
    M -= ab[1]
    total_pay += ab[1] * ab[0]
    if M < 0:
        total_pay += ab[0] * M
        break
    else:
        pass
        
print(int(total_pay))

Solution (Python):
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort()
total_drink = 0
total_pay = 0
for ab in AB:
    total_drink += ab[1]
    if M < total_drink:
        total_pay += ab[0] * (M - total_drink + ab[1])
        break
    else:
        total_pay += ab[1] * ab[0]
        
print(int(total_pay))

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

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

xy=sorted(xy)

ans=0
for p,c in xy:
    if m>=c:
        ans+=p*c
        m-=c
    else:
        ans+=p*m
        m=0
        break
print(ans)

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

for i in range(N):
    shop_i=list(map(int,input().split()))
    shop.append(shop_i)
shop.sort()

i=0
while M>0:
    if M>=shop[i][1]:
        costs+=shop[i][0]*shop[i][1]
        M-=shop[i][1]
    else:
        costs+=shop[i][0]*M
        M=0
    i+=1

print(costs)

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

A.sort()
ans=0
x=0
for val , pon in A:
	for p in range(pon):
		ans +=val
		x +=1
		if x>=M:
			print(ans)
			exit()

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

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

A.sort()

x = 0
y = 0

for i,j in A:
  if M - x < j:
    y += i * (M-x)
    break    
  else:
    x += j
    y += i * j

print(y)

Solution (Python):
n,m=map(int,input().split())
eng=[]
for i in range(n):
    eng.append([int(i) for i in input().split()])
eng.sort()
can=0
mny=0
i=0
while can<m:
    if m-can>=eng[i][1]:
        can+=eng[i][1]
        mny+=eng[i][1]*eng[i][0]
        i+=1
    else:
        mny+=eng[i][0]*(m-can)
        can=m
print(mny)

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

ABs = list(sorted(ABs))

count = M
memMoney = 0
for a,b in ABs:
    if count - b > 0:
        memMoney = memMoney + a*b
        count = count - b
        continue

    if count - b == 0:
        memMoney = memMoney + a*b
        count = count - b
        break

    d = count
    memMoney = memMoney + a*d
    count = count - d
    break

print(memMoney)

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

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

ab = sorted(ab)

ans = 0
for p, c in ab:
    if m >= c:
        ans += p * c
        m -= c
    else:
        ans += p * m
        m = 0
        break

print(ans)

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

A = []

for i in range(N):


    A.append(list(map(int, input().split())))

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

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

print(ans)

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

sum=0
honsu=0
for i in range(n):
    cost=ab[i][0]
    maxhonsu=ab[i][1]
    for _ in range(maxhonsu):
        if honsu==m:
            break
        sum+=cost
        honsu+=1

    if honsu==m:
        break

print(sum)

Solution (Python):
n,m = list(map(int,input().split()))
a = []
b = []
dic = {}
count = 0
data = [0] * n
for i in range(n):
    x,y = list(map(int,input().split()))
    data[i] = [x,y]
data = sorted(data,key = lambda x : x[0])
for i in range(n):
    if m > data[i][1]:
        count += data[i][0] * data[i][1]
        m -= data[i][1]
    else:
        count += data[i][0] * m
        break
print(count)

"""
for i in range(n):
    x,y = list(map(int,input().split()))
    dic[x] = y
dic = sorted(dic.items())



for key in dic:
    if m - dic[key] > 0:
        count += key * dic[key]
        m = m - dic[key]
    else:
        count += m * key
        break
print(count)
"""
            

"""

for i in range(n):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
count = 0


while m > 0:
    mi = min(a)
    d = a.index(mi)
    if m > b[d]  : 
        m -= b[d]
        count += b[d] * mi
    else:
        count += m * mi
        break
    del a[d]
    del b[d]
print(count)



"""

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

def getKey(item):
    return item[0]

arr.sort(key=getKey)

ans=0
for i in range(N):
    if M==0:
        break
    a,b=arr[i]
    if M >= b:
        ans=ans+(b*a)
        M = M - b
    else:
        ans=ans+(M*a)
        M=0

print(ans)

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

a = []
b = []
for i in range(n):
    a.append(ab[i][0])
    b.append(ab[i][1])

import numpy as np

a_argsort = np.argsort(a)
counter_m = 0
counter_money = 0
for i in range(n):
    idx = a_argsort[i]
    _b = b[idx]
    _a = a[idx]
    if counter_m + _b >= m:
        buy = m - counter_m
        counter_money += buy * _a
        break
    else:
        counter_m += _b
        counter_money += _a * _b

print(counter_money)

Solution (Python):
n, m = [int(i) for i in input().split()]
count=0
list=list([])
while count < n:
    list.append([int(i) for i in input().split()])
    count+=1
count=0
amount=0
for l in sorted(list):
    c = l[1] if m-count>l[1] else m-count
    amount += l[0]*c
    count += c
    if count == m:
        break
print(amount)

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

c=i=0
while M:
    if (s[i][1]<M):
        c += s[i][0]*s[i][1]
        M -= s[i][1]
    else:
        c += s[i][0]*M
        M = 0
    i+=1
print(c)

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

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

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

dict = {}

for i in range(n):
    a, b = [int(j) for j in input().split()]
    if  (a in dict):
        dict[a] = b + dict[a]
    else:
        dict[a] = b

sum = m
price = 0

for k, v in sorted(dict.items()):
    if sum > v:
        sum -= v
        price += k * v
    else:
        price += k * sum
        break

print(price)

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

minCost = 0
for (cost,q) in stores:
    if(q > M):
        minCost += M*cost
        break
    else:
        M -=q
        minCost += q*cost
print(minCost)

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

print(value)

Solution (Python):
N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
AB.sort()
money = 0
while M > 0:
  Ai, Bi = AB[0][0], AB[0][1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB[0])
print(money)

Solution (Python):
from operator import itemgetter

NM = list(map(lambda x: int(x), input().split()))
N = NM[0]
M = NM[1]

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

answer = 0
stock = 0
for store in stores:
  if (M > store[1]):
    M = M - store[1]
    answer += store[0] * store[1]
  else:
    answer += store[0] * M
    break

print(answer)

Solution (Python):


N, M = map(int, input().split())
NL = []
summoney = []
min = 1000000000

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

NL = sorted(NL)

for j in range(N):
    if M - NL[j][1] >= 0:
        summoney.append(NL[j][0]*NL[j][1])
        M =  M - NL[j][1]
    elif  M - NL[j][1] < 0:
        summoney.append(M*NL[j][0])
        break

print(sum(summoney))

Solution (Python):

import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB1 = zip(A,B)
    AB2 = sorted(AB1, key=lambda t:t[0])

    m = M
    s = 0
    for ab in AB2:
        if m > ab[1]:
            m -= ab[1]
            s += ab[0] * ab[1]
        else:
            s += ab[0] * m
            break

    print(s)




def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

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

    else : para_val[a] = b
    
para_val  = sorted(para_val.items())
count = m
ans = 0

    
for i, j in para_val :
    if count > 0 :
        if j <= count :
            count = count - j 
            ans += i * j 
        else : 
            ans += count*i 
            count = 0
    else : break 
print(ans)

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

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

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

ans = 0
i = 0
while M > 0:
  A, B = E[i]
  ans += A * min(B,M)
  M = max(M-B,0)
  i+=1
print(ans)

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

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

print(ans)

Solution (Python):


n, m = map(int, input().split())
drink = []
for _ in range(n):
    drink.append([int(s) for s in input().split()])
    
drink.sort()

bottle = 0
pay = 0

for i in range(n):
    bottle += drink[i][1]
    pay += drink[i][0]*drink[i][1]
    if bottle > m:
        bottle -= drink[i][1]
        pay -= drink[i][0]*drink[i][1]
        idx = i
        break
    
if bottle != m:
    pay += (m-bottle)*drink[idx][0]

print(pay)

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

def tupVal(tup):
    return tup[0]
tupList.sort(key = tupVal)
ans = 0
for i in tupList:
    if m >= i[1]:
        ans += i[0] * i[1]
        m -= i[1]
    else:
        ans += i[0] * m
        break
print(ans)

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

ans=0
i=0
while M>0:
  A,B=E[i]
  ans+=A*min(B,M)
  M=max(M-B,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()


cnt=0
amnt=0
for i in AB:
  if cnt>=M:
    break
  elif cnt + i[1]>M:
    for j in range(1,i[1]):
      if cnt>=M:
        break
      else:
        cnt += 1
        amnt += i[0]
  else:
    cnt += i[1]
    amnt += i[0]*i[1]
print(amnt)

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


C.sort(key=lambda x:x[0])
a = 0
n = 0
for c in C:
    if n + c[1] >= M:
        a += (M-n) * c[0]
        
        break
    else:
        a += c[0] * c[1]
        n += c[1]
print(a)

Solution (Python):

import numpy


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

for i in range(N):
  AB_list.append([int(e) for e in input().split()])

AB_list.sort(reverse=False) 



sum = 0
i = 0
ans=0

while(sum!=M):
  
  if sum + AB_list[i][1] <=M: 
    
    sum = sum + AB_list[i][1] 
    ans = ans + AB_list[i][1]*AB_list[i][0] 
    
  else: 
    
    ans = ans + AB_list[i][0]*(M-sum) 
    
    sum=M 
  i=i+1
  
print(ans)

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

lst=[list(map(int,input().split())) for _ in range(n)]
sl=sorted(lst,key=lambda x:x[0])
count=0
target_row,target_b=0,0
for i in range(len(sl)):
    if count + sl[i][1] > m:
        target_row = i
        target_b = m-count
        
        break
    count+=sl[i][1]
    if i==len(sl)-1:
        target_row = i
        target_b = sl[i][1]
    
result=0
for i in range(target_row):
    result+=sl[i][0]*sl[i][1]
    
    



print(result+sl[target_row][0]*target_b)

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

v = 0
s_b = 0
lst2 = []
for a, b in lst:
    v += a * b
    s_b += b
    if s_b == m:
        print(v)
        exit()
    if s_b > m:
        lst2.append([a, b])
        break
        
lst2.append([v, s_b])
t_v = lst2[1][0] - ((lst2[1][1] - m) * lst2[0][0])
print(t_v)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
ABs = [inpl() for _ in range(N)]
ABs.sort()

ind = 0
ans = 0
cnt = 0
while cnt < M:
    ans += ABs[ind][0]
    ABs[ind][1] -= 1
    if ABs[ind][1] == 0:
        ind += 1
    cnt += 1

print(ans)

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

Solution (Python):
import heapq as hq

def main():
    n,m = list(map(int,input().split(' ')))
    shop = []
    cnt = 0
    total = 0
    for i in range(n):
        hq.heappush(shop,list(map(int,input().split(' '))))
    for i in range(n):
        price,item=hq.heappop(shop)
        if cnt + item <=m:
            cnt += item
            total += price*item
            if cnt ==m:
                break
        else:
            total += price*(m - cnt)
            break

    print(total)

if __name__ == '__main__':
    main()

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

AB.sort()

ans = 0
count = 0
for li in AB:
    if M - count >= li[1]:
        count += li[1]
        ans += li[0]*li[1]
    else:
        ans += li[0]*(M-count)
        break

print(ans)

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

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

shop.sort()

count = 0
money = 0
for i in range(N):
    if count == M:
        break
    elif count + shop[i][1] <= M:
        count += shop[i][1]
        money += shop[i][0] * shop[i][1]
    elif count + shop[i][1] > M:
        money += shop[i][0] * (M - count)
        count += M - count

print(money)

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

ab_price = [0] * n
num = [0] * (n+1)

for i in range(n):
    num[i+1] = num[i] + sorted_ab[i][1]
    ab_price[i] = sorted_ab[i][0] * sorted_ab[i][1]
    if num[i+1] >= m:
        to_here = i + 1
        break

max_price = sorted_ab[to_here-1][0]
minus_num = num[to_here] - m
ans = sum(ab_price[:to_here]) - max_price * minus_num

print(ans)

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

shop.sort()

sum = 0
remain = M
for i in range(0, len(shop)):
    price = shop[i][0]
    stock = shop[i][1]

    if remain - stock >= 0:
        sum += price * stock
        remain -= stock
    else:
        sum += price * remain
        break




print(sum)

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

drinkinfo = []  


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


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

price = 0 
numdrink = 0 


for i in range(N):
    if sorteddrink[i][1] <= (M - numdrink):
        price += sorteddrink[i][1] * sorteddrink[i][0]
        numdrink += sorteddrink[i][1]
    else:
        price += sorteddrink[i][0] * (M - numdrink)
        numdrink += (M - numdrink)

    if numdrink == M:
        break

print(price)

Solution (Python):

N, M = [int(i) for i in input().split(" ")]
AB = []
money = 0
for i in range(N):
  AB.append([int(i) for i in input().split(" ")])
BA = sorted(AB)

for i in BA:

  if i[1] < M:
    M = M - i[1]
    money += i[0] * i[1]
  else :
    money += i[0] * M
    break
  

print(money)

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


C = sorted(zip(A, B))
A, B = zip(*C)

ans, cnt, i = 0, 0, 0
while cnt < M:
	tmp = min(B[i], M - cnt)
	cnt += tmp
	ans += A[i] * tmp
	i += 1
print(ans)

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

count = [0]*(n+1)
for i in range(n):
    count[i+1] = count[i] + ab_l[i][1]

for i in range(n+1):
    if count[i] >= m:
        to_here = i
        minus_count = count[to_here] - m
        break

all_money = [0]*n
for i in range(to_here):
    all_money[i] = ab_l[i][0] * ab_l[i][1]

ans = sum(all_money) - ab_l[to_here-1][0] * minus_count

print(ans)

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

a.sort()


money = 0
for i in range(n):
    for j in range(a[i][1]):
        money += a[i][0]
        m -= 1
        
        if m == 0:
            break
    if m == 0:
        break
print(money)

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

ds.sort(key=lambda d: d[0])

cost = 0
for d in ds:
    if d[1] >= m:
        cost += m * d[0]
        break

    cost += d[0] * d[1]
    m -= d[1]

print(cost)

Solution (Python):
N,M = map(int, input().strip().split())
k = []
for i in range(N):
    a,b = map(int, input().strip().split())
    k.append((a,b))
k.sort(key = lambda x:x[0])
price = 0
for i in range(N):
    M -= k[i][1]
    price += k[i][0]*k[i][1]
    if M <1:
        break
print(price + M*k[i][0])

Solution (Python):
from operator import itemgetter

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

lists.sort(key=itemgetter(0))
mon = 0
for shop in lists:
    if shop[1] < M:
        mon += shop[0]*shop[1]
        M -= shop[1]
    else:
        mon += shop[0]*M
        break
print(mon)

Solution (Python):
N, M = map(int, input().split())
pair = [[0, 0]]*N
cost = 0
num = 0
for i in range(N):
    a, b = map(int, input().split())
    pair[i] = [a, b]

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

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

print(cost)

Solution (Python):


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

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

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

print(ans)

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

dic_drink = {}
for i in range(N):
  ai,bi = map(int,input().split())
  if ai not in dic_drink:
    dic_drink[ai] = bi
  else:
    dic_drink[ai] += bi

price = 0
for ai,bi in sorted(dic_drink.items()):
  if M <= bi:
    price += ai*M
    break
  else:
    price += ai*bi
    M -= bi
    
print(price)

Solution (Python):
import numpy as np
N, M = map(int,input().split())
S = np.empty((N,2))
sum_buy = 0
sum_money = 0

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

S = S[S[:,0].argsort(),:]

j = 0

while True:
    if sum_buy + S[j,1] < M:
        sum_buy += S[j,1]
        sum_money += S[j,1] * S[j,0]
        j += 1
    else:
        break

sum_money = sum_money + (M - sum_buy) * S[j,0]

print(int(sum_money))