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

shop=[]

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

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

ans=0
for money, num in shop:
    if M<=num:
        ans+=money*M
        break
    else:
        ans+=money*num
        M-=num

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

ans = 0
count = 0
for v in a:
  ans += v[0] * v[1]
  count += v[1]
  if count > m:
    while True:
      count -= 1
      ans -= v[0]
      if count == m:
        break
  if count == m:
    break

print(ans)

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

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

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

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

P.sort()

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

Solution (Python):



def main():
  n, m = map(int, input().split())
  ABs = []
  for _ in range(n):
    A, B = map(int, input().split())
    ABs.append((A, B))
  ABs.sort(key= lambda x:x[0])
  payment = 0
  num = 0
  for A, B in ABs:
    payment += A*B
    num += B
    if num >= m:
      print(payment - A * (num - m))
      break
    
    
  
if __name__=='__main__':
  main()

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
C = []*N
for i in range(N):
    x, y = map(int, input().split())
    C.append((x,y))
C.sort(key=itemgetter(0))

res = 0
for i,j in C:
    if M==0:
        break
    if M > j:
        res += i*j
        M -= j
    else:
        res += i*M
        M -= M
print(res)

Solution (Python):
def main():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  ab=[list(map(int,input().split())) for _ in [0]*n]
  ab=sorted(ab,key=lambda x:x[0])
  ans=0
  for i in range(n):
    l=min(ab[i][1],m)
    m-=l
    ans+=l*ab[i][0]
    if l==0:
      print(ans)
      exit()
  print(ans)
if __name__=='__main__':
  main()

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

l.sort()

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

print(cost)

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

drink.sort()
i = price = 0
remaining = m
while remaining > 0:
    a, b = drink[i]
    if remaining >= b:
        price += a * b
    else:
        price += a * remaining
    remaining -= b
    i += 1

print(price)

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


money=0
count=0
for i in range(n):
    a=l[i][0];b=l[i][1]
    if (m-count)>b :
        count+=b
        money+=a*b
    else:
        money+=a*(m-count)
        count+=(m-count)
        break
print(money)

Solution (Python):
n,m=map(int,input().split())
ab=[]
for i in range(n):
	lst=list(map(int,input().split()))
	ab.append(lst)
ab.sort()
cost=0
now=0
while m!=0:
	cost+=ab[now][0]
	ab[now][1]-=1
	m-=1
	if ab[now][1]==0:
		now+=1
print(cost)

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

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

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

Solution (Python):


(n,m) = map(int, input().rstrip().split(" "))
shop_list = list(sorted([[int(i) for i in input().rstrip().split(" ")] for j in range(n)]))

remain = m
ans = 0

for i in shop_list:
    if remain == 0:
        break
    tmp = min(remain, i[1])
    ans += i[0] * tmp
    remain -= tmp

print(ans)

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

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(key=lambda x: x[0])
price = 0
count = 0
for s in S:
  if count + s[1] < M:
    price += s[0] * s[1]
    count += s[1]
  else:
    price += s[0] * (M - count)
    break

print(price)

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

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

total_price = 0
drink_num  = 0


for i in range(N):
    drink_num += drink_store[i][1]
    if M <= drink_num:
        left = drink_num - M
        total_price += (drink_store[i][0]*drink_store[i][1]) - (drink_store[i][0]*left)
        break
    else:
         total_price += drink_store[i][0]*drink_store[i][1]

print(total_price)

Solution (Python):






from operator import attrgetter, itemgetter


import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int,ipti().split()))
    ab = [[0] * 2 for _ in range(n)]
    for i in range(n):
        ab[i] = list(map(int,ipti().split()))

    ab.sort(key=itemgetter(0))
    ans = 0

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

    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
N,M=map(int,input().split())
k=M
s=0
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A,key=lambda x:x[0])
while k>0:
  for i in range(N):
    if k>A[i][1]:
      s+=A[i][0]*A[i][1]
      k=k-A[i][1]
    else:
      s+=A[i][0]*k
      k=0
print(s)

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

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

print(cost)

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

ab.sort()
num = 0
ans = 0

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

print(ans)

Solution (Python):
n,m=map(int,input().split())
a=[]
for _ in range(n):
    a.append([int(i) for i in input().split()])
a.sort()
ans=0 ; ind=-1 ; p=0
while ans<m:
    ind+=1
    ans+=a[ind][1]
for i in range(ind):
     p+=a[i][1]*a[i][0]
p+=a[ind][0]*(a[ind][1]-(ans-m))
print(p)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
a=[]
for _ in range(n):
    a.append([int(i) for i in input().split()])
a.sort()
ans=0 ; ind=-1 ; p=0
while ans<m:
    ind+=1
    ans+=a[ind][1]
for i in range(ind):
     p+=a[i][1]*a[i][0]
p+=a[ind][0]*(a[ind][1]-(ans-m))
print(p)

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

ab.sort(key=lambda shop: shop[0])
for i in range(n):
    if (drink_num + ab[i][1]) > m:
        ans += ab[i][0] * (m - drink_num)
        drink_num += m - drink_num
        break
    ans += ab[i][0] * ab[i][1]
    drink_num += ab[i][1]
print(ans)

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

ab.sort(key=lambda shop: shop[0])
for i in range(n):
    if (drink_num + ab[i][1]) > m:
        ans += ab[i][0] * (m - drink_num)
        drink_num += m - drink_num
        break
    ans += ab[i][0] * ab[i][1]
    drink_num += ab[i][1]
print(ans)

Solution (Python):
N, M = map(int, input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort()
onedan = 0
for ab in AB:
    buy = min(ab[1], M)
    onedan += buy * ab[0]
    M -= buy
print(onedan)

Solution (Python):
n, m = map(int, input().split())
l = []
for _ in range(n): l.append([int(x) for x in input().split()])
l.sort()
s = cnt = 0
for a, b in l:
    if cnt + b < m:
        s += a*b
        cnt += b
    else:
        s += a * (m - cnt)
        break
print(s)

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

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

i,ans,cnt = 0,0,0

while cnt < m:
    ans += sorted_ab[i][0]*min(m-cnt,sorted_ab[i][1])
    cnt += min(m-cnt,sorted_ab[i][1])
    i+=1
print(ans)

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

print(ans)

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

print(ans)

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

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

t=0
cnt=0
while M>0:
    A = AB[t][0]
    B = AB[t][1]
    if M>B:
        M = M-B
        cnt+=A*B
        t+=1
    else:
        cnt += A*M
        M = 0

print(cnt)

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

ans = 0
for i in range(n):
    if lst[i][1]<m:
        ans += lst[i][0]*lst[i][1]
        m -=lst[i][1]
    else:
        ans += lst[i][0]*m
        print(ans)
        exit()

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

    res = 0
    for i in a:
        mm = min(m,i[1])
        res += i[0]*mm
        m -= mm
        if m <= 0:
            break
    print(res)

if __name__ == '__main__':
    main()

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

cnt = 0
ans = 0

i = 0
while cnt < M:
    ans += store[i][0]
    cnt += 1
    store[i][1] -= 1

    if store[i][1] == 0:
        i += 1

print(ans)

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

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

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

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

print(ans)

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

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

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

AB.sort()
d_count = 0
money = 0
j = 0

for i in range(M):
    if d_count == AB[j][1]:
        d_count = 0
        j += 1

    money += AB[j][0]
    d_count += 1
    
print(money)

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, key=lambda x: x[0])

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

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

Solution (Python):
n,m = map(int,input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ab = sorted(ab, key=lambda x: x[0])

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

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

Solution (Python):

n,m=map(int,input().split())
lists=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append((a,b))
lists=sorted(lists,key=lambda x:x[0])
ans=0
sums=0
for i in range(n):
    if sums+lists[i][1]<m:
        ans+=lists[i][0]*lists[i][1]
        sums+=lists[i][1]
    else:
        ans+=lists[i][0]*(m-sums)
        break
print(ans)

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

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

print(ans)

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

Solution (Python):
n,m = map(int,input().split())
drink = dict()
cost = list()
ans = 0
for i in range(n):
    ab = [int(i) for i in input().split()]
    if ab[0] in drink:
        drink[ab[0]] += ab[1]
    else:
        cost.append(ab[0])
        drink[ab[0]] = ab[1]

cost.sort()
for i in cost:
    if m <= drink[i]:
        ans += m*i
        break
    else:
        m -= drink[i]
        ans += i * drink[i] 
    
print(ans)

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

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

Solution (Python):
n,m = map(int,input().split())
ab_lst = [list(map(int,input().split())) for i in range(n)]
ab_lst.sort()
total_money = 0
total_number = 0

for i in range(n):
    money = ab_lst[i][0]
    number = ab_lst[i][1]
    number = min(number, m-total_number)

    total_money += number * money
    total_number += number

    if total_number==m:
        break

print(total_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()
ans = 0

for i in range(n):
    if l[i][1] <= m:
        m -= l[i][1]
        ans += l[i][0] * l[i][1]
    else:
        ans += m * l[i][0]
        break

print(ans)

Solution (Python):
import numpy as np

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

AB = np.ones([N,2])


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

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

for i in range(N):

    if count<=M: 
        count+=AB_new[i,1]
        if count<=M:
            price+=AB_new[i,0]*AB_new[i,1]
        elif count>M:
            price+=AB_new[i,0]*(M-count+AB_new[i,1])
    else:
        break

        
print(int(price))

Solution (Python):

N,M=map(int,input().split())
Drink=[]
for _ in range(N):
    a,b=map(int,input().split())
    Drink.append((a,b))
Drink.sort(key=lambda x:x[0])

Sum=0
cnt=0
for i in range(N):
    a,b=Drink[i]
    tmp=min(M-cnt,b)
    Sum+=tmp*a
    cnt+=tmp
    if cnt==M:
        break

print(Sum)

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

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

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

cost = 0
cur_num_drink = 0
for i in store:
    buy_num = min(i[1], m-cur_num_drink)
    cur_num_drink += buy_num
    cost += i[0] * buy_num
    if cur_num_drink == m:
        break

print(cost)

Solution (Python):
N ,M = (map(int , input().split()))
shop = []
for i in range(N):
    A ,B = (map(int , input().split()))
    shop.append((A ,B))
sorted_shop = sorted(shop,key = lambda x:x[0])
drink = 0
cost = 0
for a in sorted_shop:
    drink += a[1]
    cost += a[0] * a[1]
    if drink >= M:
        break
sabun = drink - M
ans = cost - (sabun * a[0])
print(ans)

Solution (Python):
N, M = map(int,input().split())
ls = sorted([tuple(map(int,input().split())) for _ in range(N)])
cnt = 0
ans = 0
for a,b in ls:
    if cnt + b >= M:
        ans += a*(M-cnt)
        break
    cnt += b
    ans += a*b
print(ans)

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

Solution (Python):
import sys
import itertools



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

AB.sort()

ans = 0
for yen, cnt in AB:
    if M == 0:
        break
    ans += yen * min(cnt, M)
    M -= min(cnt, M)
print(ans)

Solution (Python):
import sys
import itertools



read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

AB.sort()

ans = 0
while M != 0:
    for yen, cnt in AB:
        ans += yen * min(cnt, M)
        M -= min(cnt, M)
print(ans)

Solution (Python):
n , m = map(int,input().split())
dic = {}
for _ in range(n):
    lis = list(map(int,input().split()))
    a = lis[0]
    b = lis[1]
    if a not in dic:
        dic[a] = b
    else:
        dic[a] += b
s = sorted(dic.items())

answer = 0
for ss in s:
    if ss[1]>=m:
        answer += m*ss[0]
        print(answer)
        exit()
    else:
        answer += ss[1]*ss[0]
        m -= ss[1]
        continue

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

v = 0
ans = 0

for a, b in l:
    if b+v >= M:
        ans += a*(M-v)
        break
    else:
        ans += a*b
        v+=b

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

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

honsu=0
cost=0
for i in range(N):
  honsu+=data[i][1]
  cost+=data[i][0]*data[i][1]
 
  if honsu>M:
    cost=cost-((honsu-M)*data[i][0])
    print(cost)
    exit()
print(cost)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n,m=mii()
arr=llint(n)

arr.sort()
ncnt=0
mcnt=0

for i in range(n):
    if ncnt ==m:
        continue
    elif ncnt + arr[i][1]<m:
        ncnt+=arr[i][1]
        mcnt+=arr[i][0]*arr[i][1]

    elif ncnt + arr[i][1]>=m:
        mcnt+=(m-ncnt)*arr[i][0]
        ncnt=m
print(mcnt)

Solution (Python):
N, M = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for _ in range(N)]
ab.sort(key=lambda x: x[0])
ans = 0
for a, b in ab:
    m = M
    M = max(M-b, 0)
    ans += a*(m-M)
print(ans)

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

li.sort()

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

Solution (Python):
from operator import itemgetter

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

ab.sort(key=itemgetter(0))

result = 0
for e in ab:
  count = min(m, e[1])
  result += e[0] * count
  m = max(m-count, 0)
print(result)

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

Solution (Python):
N, M = map(int, input().split())
drinks = [None] * N
for i in range(N):
    drinks[i] = tuple(map(int, input().split()))
drinks.sort()
cans = M
cost = 0
for a_cost, num in drinks:
    if cans <= 0:
        break
    dr = min(cans, num)
    cost += dr * a_cost
    cans -= dr

print(cost)

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

money=0 
num_drink=0 
for i in range(n):
    if num_drink==m:
        break
    elif num_drink + w[i][1] <= m:
        num_drink += w[i][1]
        money += w[i][0] * w[i][1]
    elif num_drink + w[i][1] > m:
        money += w[i][0] * (m - num_drink)
        num_drink += m - num_drink
print(money)

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

AB.sort()
count = 0
ans = 0
for i,j in AB:
  if count+j >= M:
    ans += (M-count)*i
    break
  else:
    count += j
    ans += j*i
print(ans)

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

ab.sort()

s = 0
ans = 0
for x, y in ab:
    if s+y>=M:
        ans += (M-s)*x
        break
    else:
        s += y
        ans += x*y
print(ans)

Solution (Python):
n,m=map(int,input().split())
ans=[]
for i in range(n):
    a,b=map(int,input().split())
    ans.append([a,b])
ans=sorted(ans,key=lambda a:a[0])
money=0
cnt=m
for i in range(n):
    price=ans[i][0]
    num=ans[i][1]
    if m>0:
        if m <= num:
            money += m*price
            m=0
        else:
            m -= num
            money+=num*price
    elif m==0:
        break
print(money)

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

y,x = 0,0
for i in range(n):
    for j in range(l[i][1]):
        if m > x:
            y += l[i][0]
            x += 1
        else:
            break

print(y)

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

    ans = 0

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

    for i in range(n):
        if m <= 0:
            break
        if m >= num_list[i][1]:
            ans += num_list[i][0] * num_list[i][1]
            m -= num_list[i][1]
        else:
            ans += num_list[i][0] * m
            break

    print(ans)

if __name__ == '__main__':
    main()

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

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

AB.sort(reverse=True)

m = 0
ans = 0
while True:
  a, b = AB.pop()
  if m + b < M:
    ans += a*b
    m += b
  else:
    c = M - m
    ans += a*c
    break

print(ans)

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

Solution (Python):
def main():
    N,M=map(int,input().split())
    X=[[0,0] for i in range(0,N)]
    for i in range(0,N):
        X[i][0],X[i][1]=map(int,input().split())

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

if __name__ == '__main__':
    main()

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

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


_cnt=0
_sum=0
i=0
if N==1 or drink_list[i][1]>=M:
    _sum=drink_list[i][0]*M
else:
    while _cnt<=M:
        if _cnt+drink_list[i][1]>=M:
            break
        else:
            _sum+=drink_list[i][0]*drink_list[i][1]
            _cnt+=drink_list[i][1]
            i+=1
        
    _sum+=drink_list[i][0]*(M-_cnt)

print(_sum)

Solution (Python):
N,M=map(int,input().split())
lis = [None]*N
for i in range(N):
    lis[i] = list(map(int,input().split()))
lis2=sorted(lis)
money=0
number = 0
i=0
while True:
    if number+lis2[i][1]<M:
        number+=lis2[i][1]
        money+=lis2[i][0]*lis2[i][1]
        i+=1
    elif number+lis2[i][1] == M:
        money+=lis2[i][0]*lis2[i][1]
        break
    else:
        temp = M-number
        money+=lis2[i][0]*temp
        break
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=sorted(l)


p=0
v=m
for i in range(n):
	if l[i][1]<=v:
		p+=l[i][0]*l[i][1]
		v=v-l[i][1]
		if v==0:
			print(p)
			exit()
	else:
		p+=v*l[i][0]
		print(p)
		exit()

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

tot,cnt=0,0
for i in range(n):
  if cnt+drink[i][1]>=m:
    tot+=drink[i][0]*(m-cnt)
    break
  else:
    cnt+=drink[i][1]
    tot+=drink[i][0]*drink[i][1]

print(tot)

Solution (Python):
N,m = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
    cnt+=A[i][0]*min(m,A[i][1])
    m-=min(m,A[i][1])
print(cnt)

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

sum = 0
cnt = 0
for ab in AB:
    a,b = ab[0], ab[1]
    if cnt + b < M:
        sum += a * b
        cnt += b
    else:
        sum += a * (M-cnt)
        break
print(sum)

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


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

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

answer, count = 0, 0
for a, b in AB:
    answer += a * b
    count += b
    if count >= m:
        answer -= a * (count - m)
        break

print(answer)

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)

Solution (Python):
n, m = map(int, input().split())
l = [0 for _ in range(n)]
for i in range(n):
    l[i] = list(map(int, input().split()))
l_sort = sorted(l)
ans = 0
drink = 0
for j in range(n):
    cnt_lim = l_sort[j][1]
    cnt = 0
    while cnt < cnt_lim:
        ans += l_sort[j][0]
        cnt += 1
        drink += 1
        if drink == m:
            print(ans)
            exit()

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