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

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

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

ABs.sort()
ans = 0
for a, b in ABs:
    num = min(b, M) 
    ans += num * a
    M -= num
print(ans)

Solution (Python):
N,M=map(int,input().split())
shop = [list(map(int,input().split())) for _ in range(N)]
shop = sorted(shop,key=lambda x: x[0])
ans=0
for i in range(N):
    if M >= shop[i][1]:
        M = M - shop[i][1]
        ans = ans + shop[i][0] * shop[i][1]
        if M == 0:
            break
    else:
        ans = ans + shop[i][0] * M
        break
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(key=lambda a: a[0])
ans = 0
for i in ab:
    buy = min(m, i[1])
    ans += buy * i[0]
    m -= buy

print(ans)

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


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

data.sort()

while m>0:
    num = m if m<data[0][1] else data[0][1]
    sum+=data[0][0]*num
    m-=num
    del data[0]

print(sum)

Solution (Python):

import sys, heapq                                                                                       


                                                                                                        
def solve(lines):                                                                                       
    N,M = map(int, lines.pop(0).split(' '))                                                             
    NLIST = []                                                                                          
    for i in range(N):                                                                                  
        A,B = map(int, lines.pop(0).split(' '))                                                         
        heapq.heappush(NLIST, (A, B))                                                                   
                                                                                                        
    res = 0                                                                                             
    while(True):                                                                                        
        p = heapq.heappop(NLIST)                                                                        
        if ( p[1] >= M ):                                                                               
            res += M * p[0]                                                                             
            break                                                                                       
        else:                                                                                           
            res += p[0] * p[1]                                                                          
            M -= p[1]                                                                                   
                                                                                                        
                                                                                                        
    print(res)                                                                                          
                                                                                                        
lines = [x.strip() for x in sys.stdin.readlines()]                                                      
                                                                                                        



solve(lines)

Solution (Python):
n,m = (int(num) for num in input().split())
list_drink = []
for i in range(n):
    list_drink.append([int(num) for num in input().split()])
list_drink.sort(key=lambda array: array[0])

num_drink = 0
cost = 0
while m>0:
    price = list_drink[num_drink][0]
    quantity = list_drink[num_drink][1]
    if quantity < m:
        cost += price*quantity
        m -= quantity
        num_drink += 1
    else:
        cost += price*m
        m = 0
        num_drink += 1
print(cost)

Solution (Python):
import numpy as np

n, m = map(int, input().split())
a = np.zeros(n)
b = np.zeros(n)
for i in range(n):
  a[i], b[i] = map(int, input().split())
idx = np.argsort(a)
a = a[idx]
b = b[idx]
price = 0
for i in range(n):
  if m <= b[i]:
    price += m * a[i]
    m = 0
  else:
    price += b[i] * a[i]
    m -= b[i]
  if m == 0:
    break
print(int(price))

Solution (Python):
if __name__ == '__main__':
    N, M = map(int, input().split())
    drinks = [tuple(map(int, input().split())) for _ in range(N)]

    drinks.sort()
    ans = 0
    for drink in drinks:
        cost, num = drink
        buy_num = min(num, M)

        ans += cost * buy_num
        M -= buy_num

        if M == 0:
            break

    print(ans)

Solution (Python):
n, m = map(int, input().split())
shop = []
for i in range(n):
    shop.append(list(map(int, input().split())))
shop.sort()
i = 0
tot_b = 0
while tot_b < m:
    tot_b += shop[i][1]
    i += 1
i -= 1
if tot_b == m:
    cost = 0
    for k in range(i+1):
        cost += shop[k][0]*shop[k][1]
    print(cost)
if tot_b > m:
    cost = 0
    for k in range(i):
        cost+= shop[k][0]*shop[k][1]
    cost += shop[i][0]*(shop[i][1]+m-tot_b)
    print(cost)

Solution (Python):
N, M = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
X.sort(key=lambda x: x[0])
i = 0
num = 0
ans = 0
while i <= N - 1:
    num += X[i][1]
    ans += X[i][0] * X[i][1]
    if num > M:
        ans -= X[i][0] * (num - M)
        break
    i += 1
print(ans)

Solution (Python):
import numpy as np

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

for i in range(0, N):
    a, b = np.array(list(map(float, input().split())))
    A.append((a, b))

dtype = [('key', int), ('value', int)]
arrayA = np.array(A, dtype=dtype)
arrayA = np.sort(arrayA, order=['key'])
cnt = 0
sum = 0
flag = 0
for j in range(0, N):
    pay = arrayA[j][0]
    num = arrayA[j][1]
    if cnt + num < M :
        cnt += num
        sum += pay*num
    else :
        diff = int(M - cnt)
        for t in range(0, diff):
            sum += pay
            cnt += 1
            if cnt == M :
                flag = 1
                print(int(sum))
                break
    if flag == 1:
        break

Solution (Python):
N, M = map(int, input().split())
x = sorted([list(map(int, input().split())) for i in range(N)])
i = 0
price = 0
minprice = x[i][0]
minnumber = x[i][1]
while True:
    if minnumber >= M:
        price += minprice*M
        break
    else:
        price += minprice * minnumber
        M -= minnumber
        i += 1
        minprice = x[i][0]
        minnumber = x[i][1]
print(price)

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

ab.sort()

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

Solution (Python):
N,M = map(int,input().split())
stores = []
for _ in range(N):
    price,stock = map(int,input().split())
    stores.append((price,stock))
stores = sorted(stores, key=lambda t: t[0])
total_cost = 0
for store in stores:
    price, stock = store[0], store[1]
    if M > stock:
        M -= stock
        total_cost += price * stock
    elif M <= stock:
        total_cost += price * M
        break
print(total_cost)

Solution (Python):
import sys
n, m,*l = map(int, sys.stdin.read().split())

a = 0
for p, q in sorted(zip(l[::2],l[1::2])):
  a += p*min(q,m)
  m -= q
  if m <= 0:
    print(a)
    break

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

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

tot = 0
i = 0
while True:
    if m == 0:
        break
    a, b = L[i]
    if m <= b:
        tot += a*m
        m = 0
    else:
        m -= b
        tot += a*b
    i += 1

print(tot)

Solution (Python):
n,m = (int(i) for i in input().split())
a = []
for i in range(n):
  tp1,tp2 = (int(i) for i in input().split())
  a.append([tp1,tp2])
drink = 0
ans = 0
a.sort()
for i in range(n):
  if drink < m:
    if drink + a[i][1] < m:
      drink += a[i][1]
      ans += a[i][0]*a[i][1]
    else:
      honsuu = m-drink
      drink += honsuu
      ans += a[i][0]*honsuu
      
  
 
print(ans)

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

def main():
  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]
      return cost
  return cost
  
print(main())

Solution (Python):
def compute():
    from sys import stdin
    N, M = map(int, stdin.readline().split())
    ipt = sorted(
            [tuple(map(int, stdin.readline().split())) for _ in range(N)],
            key=lambda x: (-x[0], x[1])
          )

    out = 0
    while (M>0) and (len(ipt)>0):
      a, b = ipt.pop()
      b = min(b,M)
      out += a*b
      M -= b

    print(out)


if __name__ == "__main__":
    compute()

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

ans = 0

ab.sort()

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

print(ans)

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

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

shoplist.sort()


cost = 0

curr = 0


while(curr<m):

	for shop in shoplist:

		if(curr+shop[1] <= m):
			curr += shop[1]
			cost += shop[0]*shop[1]

		elif(curr+shop[1]>m):

			cost += (m-curr)*shop[0]
			curr = m

print(cost)

Solution (Python):

N, M = map(int, input().split())
L = sorted(list(map(int, input().split())) for _ in range(N))

ans = 0
cnt = 0
for A, B in L:
    if cnt + B > M:
        ans += A * (M - cnt) if cnt + B > M else B
        break
    ans += A * B
    cnt += B

print(ans)

Solution (Python):
N, M = list(map(int, input().split()))
ShopList = [tuple(map(int, input().split())) for i in range(N)]
ShopList.sort()
Purchased = 0
Payment = 0

while Purchased < M:
    for shop in ShopList:
        if Purchased + shop[1] <= M:
            Payment += shop[0] * shop[1]
            Purchased += shop[1]
        elif Purchased + shop[1] > M:
            Payment += shop[0] * (M - Purchased)
            Purchased = M

print(Payment)

Solution (Python):
N, M = map(int, input().split(" "))
temp = {}
cost = 0
count = 0

for i in range(N) :
    A, B = map(int, input().split(" "))
    if A in temp :
        temp[A] += B
    else :
        temp[A] = B

for k, v in sorted(temp.items()):
    cost += k*v
    M = M - v
    
    if M <= 0 :
        cost = cost + (k*M)
        break


print(cost)

Solution (Python):
from operator import itemgetter

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

a.sort(key=itemgetter(0))
count = int(M)
price = 0
for i in range(N):
    if count - int(a[i][1]) > 0:
        count -= int(a[i][1])
        price += int(a[i][1]) * int(a[i][0])
    else:
        price += int(a[i][0]) * count
        break

print(price)

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

Solution (Python):
import sys

N, M = map(int, sys.stdin.readline().split())
AB = [None] * N
for i in range(N):
    AB[i] = list(map(int, sys.stdin.readline().split()))

AB.sort()
cnt = 0
ans = 0

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

print(ans)

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

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

Solution (Python):
N, M = map(int,input().split())
count = yen = imp = 0
li = [list(map(int,input().split())) for i in range(N)]
li.sort()
for i in range(0,len(li),1):
  count += li[i][1] 
  yen += li[i][0]*li[i][1] 
  if count > M:
    imp = abs(M-count)
    count -= abs(M-count)
    yen -= li[i][0]*imp
  if count == M: 
    break
print(yen)

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

AB = sorted(AB)
cnt = 0
ans = 0

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

print(ans)

Solution (Python):

n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
i = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
    i += 1
sumMoney += abSorted[i][0] * (m - sumB)
print(sumMoney)

Solution (Python):

n,m = map(int,input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
abSorted = sorted(ab)
sumB = 0
sumMoney = 0
i = 0
while sumB + abSorted[i][1] < m:
    sumB += abSorted[i][1]
    sumMoney += abSorted[i][0] * abSorted[i][1]
    i += 1
sumMoney += abSorted[i][0] * (m - sumB)
print(sumMoney)

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

Solution (Python):
def solve(l: list, m: int):
    
    l = sorted(l)
    cnt = 0
    mon = 0
    for a, b in l:
        mon += a*b
        cnt += b
        if cnt >= m:
            mon -= (cnt-m)*a
            break
    return mon


def main():
    N, M = map(int, input().split())
    l = []
    for i in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    print(solve(l, M))


if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce
N, M = map(int, input().split())
A, B = zip(*sorted((list(map(int, input().split())) for _ in range(N))))
ans = reduce(lambda acc, t: (acc[0] + t[0] * min(max(0, M - acc[1]), t[1]), acc[1] + t[1]), zip(A, B), (0, 0))[0]
print(ans)

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])
ans=0
for i in range(n):
    buy=min(m,A[i][1])
    ans+=buy*A[i][0]
    m-=buy
print(ans)

Solution (Python):
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
index = 0
count = 0
sum = 0
for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)

Solution (Python):
from sys import stdin
n,s = map(int,stdin.readline().split())
ans = 0
a = []
for i in xrange(n):
  x,y = map(int,stdin.readline().split())
  a.append((x,y))
a.sort()
for x,y in a:
  mi = min(y,s)
  ans += mi * x
  s -= mi
print ans

Solution (Python):
import numpy as np
N,M=[int(x) for x in input().split()]

L=np.zeros((2,N))
for n in range(N):
  l=[int(x) for x in input().split()]
  L[0][n]=l[0]
  L[1][n]=l[1]
  
L=L[:, L[0,:].argsort()]

d_num=0
price=0

for l in range(len(L[0])):
  a=L[0][l]
  b=L[1][l]
  
  if d_num < M:
    if d_num+b < M:
      price+=a*b 
      d_num+=b 
    else:
      price+=a*(M-d_num)
      d_num=M
                
print(int(price))

Solution (Python):
var = list(map(int, input().split()))
N = var[0]
M = var[1]
 
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
 
index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[i]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)

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


total=0
for i in range(n):
    if m > 0:
      total+=e[i][0]*min(e[i][1],m)
    m-=e[i][1]
    
print(total)

Solution (Python):
import numpy as np
import sys

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

ab = np.zeros((2,N))
for i in range(N):
  ab[0, i], ab[1, i] = [int(item) for item in input().split()]
  
ab = ab[:,np.argsort(ab[0, :])]

num = 0
money = 0
for i, item in enumerate(ab[1,:]):
  num += item
  money += item * ab[0,i]
  if num >= M:
    money -= (num - M) * ab[0,i]
    print(int(money))
    break

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
num = M
for a,b in AB:
  if b < num:
    ans += a*b
    num -= b
  else:
    ans += a*num
    num -= num
    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()

res = 0
count = 0

for A,B in AB:
    if  B <= M - count:
        count += B
        res += A * B
    else:
        res += A * (M - count)
        count = M

    if count == M:
        break

print(res)

Solution (Python):
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(n)]
lis.sort()
to = 0
nu = 0
for i in lis:
    for n in range(i[1]):
        to += i[0]
        nu += 1
        if nu == m:
            print(to)
            exit()

Solution (Python):




def two_dim_merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    
    left = arr[:mid]
    right = arr[mid:]

    
    left = two_dim_merge_sort(left)
    right = two_dim_merge_sort(right)

    
    return two_dim_merge(left, right)


def two_dim_merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    
    while l_i < len(left) and r_i < len(right):
        
        if left[l_i][0] <= right[r_i][0]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged



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

l = [0]*n

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

s = two_dim_merge_sort(l)

num = 0
ex = 0

for i in range(0,n):
    if num + s[i][1] <= m:
        ex = ex + s[i][0] * s[i][1]
        num = num + s[i][1]
    else:
        ex = ex + s[i][0] * (m-num)
        num = m
    if num == m:
        break
        
print(ex)

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

inputs.sort()
count = 0
ans = 0
for A, B in inputs:
    if M < 0:
        break
    ans += A * min(B, M)
    M -= B

print(ans)

Solution (Python):
m = list(map(int,input().split()))
l = sorted([list(map(int,input().split())) for i in range(m[0])], key=lambda x: x[0])
r = 0
c = 0
for a in l:
  if (c + a[1]) >= m[1]:
    r += a[0] * (m[1] - c)
    break
  c += a[1]
  r += a[0] * a[1]
print(r)

Solution (Python):
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
ct1=0
ct2=0
money=0
l=[]
id=[]
for i in range(N):
    l.append(ab[i][0])
id=sorted(range(len(l)),key=lambda k: l[k])
l.sort()
while ct<M:
    while ct2<ab[id[ct1]][1]:
        money+=l[ct1] 
        
        ct+=1
        ct2+=1
        if ct==M:
            break
    ct1+=1
    ct2=0
print(money)

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

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

A = [None] * N
B = [None] * N

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

C = zip(A, B)
C = sorted(C, key=lambda x: [x[0], x[1]], reverse=False)
A, B = map(list, zip(*C))

m = 0
r = 0

for i in range(N):
    a = A[i]
    b = B[i]
    if m + b < M:
        m += b
        r += a * b
    else:
        r += a * (M - m)
        break

print(r)

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

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


N, M = inpl()
AB = [inpl() for _ in range(N)]

AB.sort()
ans = 0
i = 0
while M != 0:
    ans += min(M, AB[i][1]) * AB[i][0]
    M -= min(M, AB[i][1])
    i += 1
print(ans)

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(key=lambda x:x[0])
i=0
ans=0
while M>l[i][1]:
  M-=l[i][1]
  ans+=l[i][0]*l[i][1]
  i+=1
ans+=l[i][0]*M
print(ans)

Solution (Python):
from operator import itemgetter
N,M = [int(x) for x in input().split()]
li = []
for _ in range(N):
    li.append([int(x) for x in input().split()])
li.sort(key=itemgetter(0))
cost = 0
num = 0
flag = True
for i in li:
    if(flag):
        if(num+i[1]>M):
            cost+=(M-num)*i[0]
            flag = False
        else:
            cost+=i[1]*i[0]
            num+=i[1]
print(cost)

Solution (Python):
n, m = map(int, input().split())
st = []
for _ in range(n):
    st.append(tuple(map(int, input().split())))
st.sort()
i = 0
c = 0
while m > 0:
    b = min(m, st[i][1])
    c += b * st[i][0]
    m -= b
    i += 1
print(c)

Solution (Python):
N, M = map(int, input().split())
x = sorted([list(map(int, input().split())) for i in range(N)])
i = 0
minprice = x[i][0]
minnumber = x[i][1]
price = 0
while True:
    if M <= minnumber:
        price += minprice * M
        break
    else:
        price += minprice * minnumber
        M -= minnumber
        i += 1
        minprice = x[i][0]
        minnumber = x[i][1]
print(price)

Solution (Python):
import sys
N, M = (int(x) for x in input().split())
AB = []
for i in range(N):
    AB_before = input().split()
    AB.append([int(x) for x in AB_before])

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

count = 0
total = 0

for i in range(N):
    if count < M - AB[i][1]:
        total += AB[i][0] * AB[i][1]
        count += AB[i][1]
    elif count < M:
        total += AB[i][0] * (M - count)
        print(total)
        sys.exit()

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

for i in range(0, n):
    ab.append([int(i) for i in input().split(" ")])
    
ab = sorted(ab, key=lambda k: k[0])

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

Solution (Python):
N,M = map(int,input().split())
list = []
for i in range(N):
    A,B = map(int,input().split())
    list.append([A,B])
list = sorted(list)
cost = 0
while True:
    M -= list[0][1]
    if M <= 0:
        cost += list[0][0] * (list[0][1]+M)
        break
    else:
        cost += list[0][0] * list[0][1]
        list.remove(list[0])
print(cost)

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

shop_s=sorted(shop)
count=0
used_money=0

for s in shop_s:
    for i in range(s[1]):
        if(M!=count and s[1]!=0):
            s[1]-=1
            count+=1
            used_money += s[0]
        else:
            break
    if  count == M:
        break
print(used_money)

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

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

shoplist.sort(key=lambda x: x[0])
rtn=0
for elm in shoplist:
  if M==0:
    break
  if M >= elm[1]:
    rtn+=elm[0]*elm[1]
    M-=elm[1]
  else:
    rtn+=elm[0]*M
    M=0
print(rtn)

Solution (Python):




N,M = map(int, input().split())
ABn = [[0 for j in range(2)] for i in range(N)]
for i in range(N):
  ABn[i] = list(map(int, input().split()))

ABn = sorted(ABn)

num,i = M,0
ans = 0
while(num > 0):
  if num >= ABn[i][1]:
    ans += ABn[i][0] * ABn[i][1]
    num -= ABn[i][1]
  else:
    ans += ABn[i][0] * num
    num = 0
  i += 1
print(ans)

Solution (Python):
N, M = map(int, input().split())
num = 0
price = 0
for A, B in sorted([list(map(int, input().split())) for _ in range(N)]):
    if M >= B:
        price += A*B
        M = M - B
    else:
        price += A*M
        break
print(price)

Solution (Python):


"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""

N, M = tuple(map(int, input().split()))
AtoB = []
for i in range(N):
    AtoB.append(tuple(map(int, input().split())))
AtoB.sort()
cost = 0
m = 0
lastorder = 0
history = []

for i in range(len(AtoB)):
    cost += AtoB[i][0]*AtoB[i][1]
    m += AtoB[i][1]
    lastorder = AtoB[i][0]
    if M <= m:
        break
while M < m:
    cost -= lastorder
    m -= 1

print(cost)

Solution (Python):
N, M = map(int, input().split())
mseList = [list(map(int, input().split())) for i in range(0, N)]
mseList = sorted(mseList, key=lambda x:x[0])
total = 0
for i, k in mseList:
    if k < M:
        total += i * k
        M -= k
    else:
        total += i * M
        break
print(total)

Solution (Python):
import numpy as np
N, M = (int(i) for i in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB.sort()
for a, b in AB:
    if M == 0:
        break
    elif M >= b:
        M -= b
        money += a*b
    elif M < b:
        money += M*a
        M = 0
print(money)

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

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


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)

Solution (Python):
import numpy as np
N, M = (int(i) for i in input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
money = 0
for a, b in AB:
    if M == 0:
        break
    elif M >= b:
        M -= b
        money += a*b
    elif M < b:
        money += a*M
        M = 0
print(money)

Solution (Python):
n,m = map(int,input().split(' '))
cost = 0
count = 0

mlist = list()
for i in range(n):
  mlist.append(list(map(int,input().split(' '))))
mlist.sort(key=lambda x: x[0])

for i in range(n):
  ablist = mlist[i]
  if count+ablist[1] <= m:
    count += ablist[1]
    cost += ablist[0]*ablist[1] 
  else:
    for j in range(ablist[1]):
      count += 1
      if count <= m:
        cost += ablist[0]
      else:
        break_t = True
        break
    if break_t:
      break
print(cost)

Solution (Python):
n,m=map(int,input().split())
ab=[list(map(int,input().split()))for i in range(n)]
ab=sorted(ab, key=lambda x:x[0])
i=0
money=0
while True:
    if m-ab[i][1]>0:
        m-=ab[i][1]
        money+=ab[i][0]*ab[i][1]
        i+=1
    else:
        break
money+=m*ab[i][0]
print(money)

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

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

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

ans = 0
for i in range(len(L)) :
    if L[i][1] < M :
        M -= L[i][1]
        ans += L[i][0] * L[i][1]
    else :
        ans += L[i][0] * M
        break
print(ans)

Solution (Python):



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

AB.sort()


money = 0
for a, b in AB:

    
    if M==0:
        break
    elif b < M:
        
        money += a*b
        M -= b
    elif b >= M:
        
        money += M*a
        M = 0
    
print(money)

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

Solution (Python):

import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB = sorted(range(N), key=lambda x: A[x])

    s = 0
    for i in AB:
        if B[i] > M:
            s += M*A[i]
            break
        else:
            s += A[i]*B[i]
            M -= B[i]

    print(s)
    return



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



def main():
    n, m = map(int, input().split())
    ab = list()
    ans = 0

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

    for aj, bj in sorted(ab, key=lambda x: x[0]):
        if m >= bj:
            ans += aj * bj
            m -= bj
        else:
            ans += aj * m
            break

    print(ans)


if __name__ == '__main__':
    main()