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

Solution (Python):
from sys import stdin
import sys
N, M = [int(x) for x in stdin.readline().rstrip().split()]
A = []
for _ in range(N):
    temp = [int(x) for x in stdin.readline().rstrip().split()]
    A.append(temp)
A = sorted(A, key = lambda x: x[0])
ans = 0
for i in range(N):
    a = min(M, A[i][1])
    ans += a * A[i][0]
    M -= a
    if M == 0:
        print(ans)
        sys.exit()

Solution (Python):
import heapq

N, M = map(int, input().split())
A_B = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(A_B, (a, b))

count = 0
price = 0
while count < M:
    a_b = heapq.heappop(A_B)
    count += a_b[1]
    price += a_b[1] * a_b[0]

print(price - (count-M)*a_b[0])

Solution (Python):
import sys
input = sys.stdin.readline
def print_ans(N, M, arr):
    """Test Case
    >>> print_ans(2, 5, [[4, 9], [2, 4]])
    12
    >>> print_ans(4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]])
    130
    >>> print_ans(1, 100000,[[1000000000, 100000]])
    100000000000000
    """
    ans = 0
    tmp = M
    arr = sorted(arr)
    for ar in arr:
        if tmp > ar[1]:
            ans += ar[0] * ar[1]
        else:
            ans += ar[0] * tmp
            break
        tmp -= ar[1]
    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().rstrip().split())
    arr = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, M, arr)

Solution (Python):
def main():
    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])
    c=0
    for a,b in ab:
        if m>b:
            c+=a*b
            m-=b
        else:
            c+=a*m
            print(c)
            return
main()

Solution (Python):
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a=sorted(a, key=lambda x: x[0])
res=0
i=0
while True:
    if m==0:
        print(res)
        exit()
    if a[i][1]!=0:
        a[i][1]-=1
        res+=a[i][0]
        m-=1
    else:
        i+=1
        a[i][1]-=1
        res+=a[i][0]
        m-=1

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

ABn =[ list(map(int,input().split(' '))) for _ in range(N)]  
ABn.sort(key=lambda x:(x[0]))
amount_yen = 0
for i in range(N):
    if ABn[i][1] < M:
        M -= ABn[i][1]
        amount_yen += ABn[i][0] * ABn[i][1]
    else:
        amount_yen += ABn[i][0] * M
        break
print(amount_yen)

Solution (Python):

import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        total +=a*m
        print(total)
        break

Solution (Python):
n, m = map(int, input().split())
L = []
for i in range(n):
  L.append(list(map(int, input().split())))
  
L.sort(key=lambda store: store[0])
price = 0
for i in range(n):
    price += L[i][0] * min(m, L[i][1])
    m -= min(m, L[i][1])
    if m <= 0:
      print(price)    
      exit()

Solution (Python):
N,M=map(int,input().split())
X=[]
for i in range(N):
  a,b=map(int,input().split())
  X +=[[a,b]]
X.sort()
answer=0
i=0
while M>0:
  if X[i][1]<=M:
    answer +=X[i][0]*X[i][1]
  elif X[i][1]>M:
    answer +=M*X[i][0]
  M -=X[i][1]
  i+=1
print(answer)

Solution (Python):
n,m=map(int,input().split())
d={}
for i in range(n):
      a,b=map(int,input().split())
      if a in d:
            d[a]+=b
      else:
            d[a]=b
d = list(sorted(d.items(), key=lambda x:x[0]))

dd=[]
for i in d:
      dd.append([i[0],i[1]])

ans=0
i=0
c=0
while m>c:
      if dd[i][1]!=0:
            dd[i][1]+=-1
            ans+=dd[i][0]
            c+=1
      else:
            i+=1
     
print(ans)

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

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])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=1
    else:
      break
print(ans)

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


def main():
    n, m = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]
    ab.sort()
    ans = 0

    for a, b in ab:
        if m > b:
            m -= b
            ans += a*b

        else:
            print(ans+a*m)
            break


if __name__ == '__main__':
    main()

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

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

AB = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
idx = 0
while M:
    
    b = min(M, AB[idx][1])
    ans += AB[idx][0] * b
    M -= b
    idx += 1
    
print(ans)

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



cost = 0
for i in range(n) :
  a,b = ab[i]
  c = m - b
  if 0 <= c :
    cost += a*b
    m -= b    

  else :
    cost += a*m
    m = 0    

  if m == 0 :
    print(cost)
    break

Solution (Python):
def main():
  n, m = map(int, input().split())
  shops = sorted([list(map(int, input().split())) for i in range(n)])
  
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      break
  print(cost)
  

if __name__ == '__main__':
  main()

Solution (Python):
import heapq

h = []
n, m = list(map(int, input().split()))
for _ in range(n):
  a, b = list(map(int, input().split()))
  heapq.heappush(h, (a, b))

cost = 0
while True:
  (a, b) = heapq.heappop(h)
  if b < m:
    cost += a * b
    m -= b
  else:
    cost += a * m
    break

print(cost)

Solution (Python):

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

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

a,b = zip(*sorted(zip(a,b)))
ans = 0
cnt_drink = 0
pos = 0
while cnt_drink < m:
    if m - cnt_drink >= b[pos]:
        ans += b[pos]* a[pos]
        cnt_drink += b[pos]
    else: 
        ans += (m - cnt_drink) * a[pos]
        cnt_drink = m
    pos += 1
print(ans)

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

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

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

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

while True:
    if m == 0:
        print(ans)
        quit()
    if li[0][1] == 0:
        li.pop(0)
    ans += li[0][0]
    li[0][1] -= 1
    m -= 1

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

cnt_mount=0
cnt_money=0

for i in range(M):
    cnt_money +=(list_aaa[i][0])*(list_aaa[i][1])
    cnt_mount +=list_aaa[i][1]
    if cnt_mount>=M:
        cnt_money -=(cnt_mount-M)*list_aaa[i][0]
        break
print(cnt_money)

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 x:(x[0], x[1]))
ans = 0
for i in range(N):
   cost = AB[i][0]
   b = AB[i][1]
   if b < M:
      M -= b
      ans += b*cost
   else:
      ans += cost * M
      break
print(ans)

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

data = [[0,0] for _ in range(n)]
for i in range(n):
  data[i][0],data[i][1] = map(int, input().split())

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

rest = m
money = 0
for a,b in data:
  
  if b <rest:
    rest-=b
    money+=a*b
  else:
    money += a*rest
    break

print(money)

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

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

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

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

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

Solution (Python):
n,m=map(int,input().split())
d=[None]*n
for i in range(n):
  a,b=map(int,input().split())
  d[i]=[a,b]
  
d=sorted(d,key=lambda x:x[0])

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

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

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

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

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

print(money)

Solution (Python):
N,M = map(int,input().split())
drink = [list(map(int,input().split())) for n in range(N)]
drink.sort(key=lambda x: x[0])
Cnt = 0
Ttl = 0
x = 0
while Cnt < M:
  while Cnt < M and drink[x][1] > 0:
    Cnt += 1
    Ttl += drink[x][0]
    drink[x][1] -= 1
  x += 1

print(Ttl)

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

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



L.sort()
for j in range(N):
    num = L[j][1]
    if M > num:
        money = L[j][0]*L[j][1]
        M -= num
        cost += money
    elif M == 0:
        break
    else:
        money = L[j][0]*M
        cost += money
        break
print(cost)

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

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

  if cnt >= M:
    break
print(ans)

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

Solution (Python):
import collections
import fractions
N,M=map(int,input().split())
AB=sorted([list(map(int,input().split())) for i in range(N)],key=lambda x:x[0])
hon=0
yen=0
abidx=0
while M>hon:
    hon,yen=min(M-hon,AB[abidx][1])+hon,AB[abidx][0]*min(M-hon,AB[abidx][1])+yen
    abidx+=1
print(yen)

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

Solution (Python):

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


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

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

print(cost)

Solution (Python):
from operator import itemgetter
def f(ab, cnt, price, n, m):
        for i in range(n):
                if cnt + ab[i][1] > m:
                        for j in range(1, ab[i][1]):
                                cnt += 1
                                if cnt == m:
                                        price += ab[i][0] * j
                                        break
                        
                        
                        
                        break
                else:
                        cnt += ab[i][1]
                        price += ab[i][0] * ab[i][1]
                        
                        
                        
        
        
        
        
        
        return price

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


cnt = 0
price = 0


















print(f(ab, cnt, price, n, m))

Solution (Python):
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

costs, maxCanNumbers = (list(x) for x in zip(*sorted(zip(costs, maxCanNumbers))))

for i in range(storeNum):
    if canNum >= maxCanNumbers[i]:
        totalPrice = totalPrice + costs[i] * maxCanNumbers[i]
        canNum = canNum - maxCanNumbers[i]
        if canNum is 0:
            break
    else:
        totalPrice = totalPrice + costs[i] * canNum
        canNum = 0    
        break

print(totalPrice)

Solution (Python):
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

costs, maxCanNumbers = (list(x) for x in zip(*sorted(zip(costs, maxCanNumbers))))

for i in range(storeNum):
    if canNum >= maxCanNumbers[i]:
        totalPrice = totalPrice + costs[i] * maxCanNumbers[i]
        canNum = canNum - maxCanNumbers[i]
        if canNum is 0:
            break
    else:
        totalPrice = totalPrice + costs[i] * canNum
        canNum = 0    
        break

print(totalPrice)

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

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

ans = 0
now = 0
for a,b in abl:
    need = m - now
    now += min(need, b)
    ans += min(need, b) * a
    if now == m:
        break
    
print(ans)

Solution (Python):
N,M = map(int,input().split())
drink = [list(map(int,input().split())) for n in range(N)]
drink.sort(key=lambda x: x[0])
m = 0
ans = 0
while M != 0:
    if M >= drink[m][1]:
        ans += drink[m][0]*drink[m][1]
        M -= drink[m][1]
    else:
        ans += drink[m][0]*M
        M = 0
    m += 1
print(ans)

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

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

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

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

count = 0
ans = 0
for _ab in ab:
    diff = M - count
    if _ab[1] < diff:
        count += _ab[1]  
        ans += _ab[0] * _ab[1]
    else:
        ans += _ab[0] * diff
        break

print(ans)

Solution (Python):
n, m = map(int, input().split())
L = []
for i in range(n):
  L.append(list(map(int, input().split())))
L.sort(key=lambda x: x[0])
counter = 0
for pair in L:
  if m <= pair[1]:
    counter += pair[0] * m
    print(counter)
    break
  else:
    m -= pair[1]
    counter += pair[0] * pair[1]

Solution (Python):
n,m=[int(i) for i in input().split()]
a=[]
for i in range(n):
    x,y=[int(i) for i in input().split()]
    a.append([x,y])
a.sort()
curr=0
ans=0
for i in range(len(a)):
    if(a[i][1]+curr>=m):
        ans+=(m-curr)*a[i][0]
        break
    else:
        ans+=a[i][0]*a[i][1]
        curr+=a[i][1]
print(ans)

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

    A = []
    B = []
    array = []
    for i in range(n):
        array.append(tuple(map(int, input().split())))
    array_sorted = sorted(array, key=lambda item : (item[0]))

    ans = 0
    num = 0
    for pair in array_sorted:
        capacity = m-num
        if capacity >= pair[1]:
            ans += pair[0]*pair[1]
            num += pair[1]
        else:
            ans += pair[0]*capacity
            break
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    AB.sort()
    now=m
    score=0
    for a,b in AB:
        k=min(m,b)
        m-=k
        score+=a*k
        if(m==0):
            print(score)
            return
resolve()

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

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

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

Solution (Python):
import heapq

n,m = list(map(int, input().split()))
h = []
for i in range(n):
  a, b = list(map(int, input().split()))
  heapq.heappush(h, (a, b))

ans = 0
remain = m
for i in range(len(h)):
  price, count = heapq.heappop(h)
  if(remain - count <= 0):
    ans += price * remain
    print(ans)
    exit()
  else:
    ans += price * count
    remain -= count

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

d = 0
ans = 0
for _ab in ab:
    diff = m - d
    if _ab[1] - diff < 0:
        ans += _ab[0]*_ab[1]
        d += _ab[1]
    else:
        ans += _ab[0]*diff
        d += diff

print(ans)

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

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

stores.sort()
i = 0
amt = 0
while M > 0:
  if M < stores[i][1]:
    amt += stores[i][0] * M
    M =0
  else:
    amt += stores[i][0] * stores[i][1]
    M -= stores[i][1]
  i+=1

print(amt)

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

ans = 0
for i in range(N):
  ans += AB[i][0] * max(0,min(AB[i][1],M))
  M -= AB[i][1]
print(ans)

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

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

Solution (Python):
from operator import itemgetter


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

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

def main():
    b = sorted(a, key=itemgetter(0))
    
    m = 0
    cost = 0
    for i in range(N):
        
        if (m + b[i][1]) <= M:
            m += b[i][1]
            cost += (b[i][0] * b[i][1])
        else:
            cost += (b[i][0] * (M-m))
            return cost
    return cost

print(main())

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

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

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

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

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

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

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

Solution (Python):
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

li.sort(key=lambda x:(x[0],x[1]))
cost = 0

while m > 0:
    if li[0][1] > 0:
        cost += li[0][0]
        li[0][1] -= 1
        m -= 1
    else:
        li.pop(0)

print(cost)

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

drink.sort()
bought = 0
shop = 0
ans = 0
while 1:
    dif = m - bought
    if drink[shop][1] >= dif:
        ans += drink[shop][0] * dif
        break
    else:
        ans += drink[shop][0] * drink[shop][1]
        bought += drink[shop][1]
    shop += 1

print(ans)

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

list1.sort(key=operator.itemgetter(0))
count_drink = 0
count = 0
last = 0
i = 0
while m > count_drink:
    last = list1[i][1]
    while last > 0:
        if m <= count_drink:
            break
        count += list1[i][0]
        last -= 1
        count_drink += 1
    i += 1

print(count)

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


rest = M
ans = 0
for a, b in sorted(AB, key=lambda x: x[0]):
	
    if (b < rest):
        ans += a*b
        rest -= b
    else:
        ans += (a*rest)
        break
print(ans)

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

c=0
y=0

A_B_sorted=sorted(A_B)

for ab in A_B_sorted:
    c+=ab[1]
    y+=ab[0]*ab[1]

    if c>=M:
        print(y-ab[0]*(c-M))
        break

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

i = 0
ans = 0
while True:
    if store[i][1] < m:
        ans += store[i][0]*store[i][1]
        m -= store[i][1]
        i += 1
    else:
        ans += m*store[i][0]
        break
print(ans)

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

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

inventory.sort()

total = 0
spent = 0
step = 0



while total < M:
    while inventory[step][1] > 0:
        total = total + 1
        spent = spent + inventory[step][0]
        inventory[step][1] = inventory[step][1] - 1
        if total == M:
            break
        
        
        
        
    step = step + 1
    
    
    
    




print(spent)

Solution (Python):
N,M=map(int,input().split())
Drinks=sorted([list(map(int,input().split())) for i in range(N)])
Need=0
for i in Drinks:
    if M <= i[1]:
        Need+=i[0]*M
        break
    if M > i[1]:
        Need+=i[0]*i[1]
        M-=i[1]
print(Need)

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

pay = 0
to = 0
j = 0
while to < m:
	if to+ab[j][1] <= m:
		to += ab[j][1]
		pay += ab[j][0]*ab[j][1]
		j += 1
	else:
		pay += ab[j][0]*(m-to)
		to = m

print(pay)

Solution (Python):
import numpy as np
n, m = map(int, input().split())
ab = np.empty((n, 2), dtype=np.int64)
for i in range(n):
    ab[i, :] = list(map(int, input().split()))

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

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

Solution (Python):
N,M = map(int,input().split())
shop_dict ={}
for i in range(N):
    price,num = map(int, input().split())
    if  price not in shop_dict:
        shop_dict[price] = num
    else:
        shop_dict[price] += num

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


num_count = 0
money_count = 0
for i in range(N):
    
    if num_count + shop_dict[i][1] >= M:
        print(money_count + (M-num_count) * shop_dict[i][0])
     
        exit()
    num_count += shop_dict[i][1]
    money_count += shop_dict[i][0] * shop_dict[i][1]

Solution (Python):
n,m = map(int,input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
total = 0
x = sorted(x)
for i in range(0,n):
    if x[i][1] < m:
        total += x[i][0] * x[i][1]
        m -= x[i][1]
    else:
        total += x[i][0] * m
        break
print(total)

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

X = []
for _ in range(N):
    temp = list(map(int,input().split()))
    X.append(temp)
X = sorted(X)

bottle = 0
money = 0

for n in range(N):
    bottle += X[n][1]
    money += X[n][0] * X[n][1]

    if bottle >= M:
        money -= (bottle - M) * X[n][0]
        break

print(money)

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

Solution (Python):
N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
rest = M
ans = 0
for a, b in sorted(AB, key=lambda x: x[0]):
    if (b < rest):
        ans += a*b
        rest -= b
    else:
        ans += (a*rest)
        break
print(ans)

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

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

a = []
b = []
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

l = list(zip(a,b))
l.sort()

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

print(c)

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

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

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

Solution (Python):
def main():
    N, M = map(int, input().split())
    pair = []
    for i in range(N):
        A, B = map(int, input().split())
        pair.append([A, B])
    pair.sort()
    count = 0
    money = 0
    now = 0
    while True:
        if pair[now][1] + count < M:
            money += pair[now][1] * pair[now][0]
            count += pair[now][1]
        else:
            money += (M - count) * pair[now][0]
            break
        now += 1
    print(money)


if __name__ == "__main__":
    main()