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 operator import itemgetter

N_shop, M_required_drink  = map(int, raw_input().split())

shop_list = []
for tmp_shop in range(N_shop):
  shop_list.append(map(int, raw_input().split()))

total_money = 0
got_drink = 0
for i in sorted(shop_list, key=itemgetter(0)):
  limit_at_shop = i[1]


  while got_drink < M_required_drink and limit_at_shop > 0:
    total_money = total_money + i[0]
    got_drink   = got_drink + 1
    limit_at_shop = limit_at_shop - 1


print(total_money)

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

Solution (Python):
YEN = 0
NUM = 1

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

require = M
price = 0
minidx = 0
while(require > 0):


    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:

        price = price + shop[minidx][YEN] * require
        require = 0

print(price)

Solution (Python):
def main():
    n, m = map(int, input().split())
    nums = []
    for i in range(n):
        a, b = map(int, input().split())
        nums.append((a, b))
    nums.sort()
    total = 0
    for i in range(n):
        if m <= 0:
            break
        a, b = nums[i]
        total += a * min(b, m)
        m -= min(b, m)
    print(total)


if __name__ == '__main__':
    main()

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

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

a.sort()

c = 0
p = 0
left = m

for i in range(n):
	if left >= a[i][1]:
		b = a[i][1]
		c += b
		p += a[i][0] * b
		left -= b
	elif left < a[i][1]:
		c += left
		p += a[i][0] * left
		left = 0
        
	if left == 0:
		break
	
print(p)

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

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

B.sort()

k=0
l=0
m=0
money=0
X=0
for a,b in B:
    if(M<=0):
        break
    if(b<=M):
        money+=a*b
    else:
        money+=M*a
    M-=b
print(money)

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

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

A, B = [], []
for n in range(N):
  a_i, b_i = [int(num) for num in input().split()]
  A.append(a_i)
  B.append(b_i)

A_sort_index = np.argsort(A)
total_val = 0
for index in A_sort_index:
  if M < B[index]:
    total_val += M * A[index]
    break
  else:
    total_val += A[index] * B[index]
    M -= B[index]

print (total_val)

Solution (Python):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

N,M = ints_raw()
ABs = []
for n_i in xrange(N):
    ABs.append(ints_raw())
ABs.sort()

ans = 0
kosuu = 0
for A,B in ABs:
    n_kosuu = kosuu + B
    if n_kosuu>=M:
        ans += (M-kosuu)*A
        kosuu = M
        break
    else:
        ans += A*B
        kosuu = n_kosuu

print ans

Solution (Python):
n,m=map(int,input().split())
dct={}
for i in range(n):
    k,v=map(int,input().split())
    if k not in dct.keys():
        dct[k]=v
    else:
        dct[k]+=v
sdct=sorted(dct.items())
yen=0
for k,v in sdct:
    if v<=m:
        m-=v
        yen+=k*v
    else:
        yen+=k*m
        break
print(yen)

Solution (Python):
N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Solution (Python):
import sys
size_data = sys.stdin.readline().strip().split(" ")

N = int(size_data[0])
M = int(size_data[1])

shop_stock = []

for i in range(N):
    row = sys.stdin.readline().strip().split(" ")
    shop_stock.append((int(row[0]), int(row[1])))

shop_stock = sorted(shop_stock, key=lambda store: store[0])

money = 0
cans_remaining = M

for shop in shop_stock:
    price, max_cans = shop

    cans_to_buy = min(max_cans, cans_remaining)
    money += cans_to_buy * price
    cans_remaining -= cans_to_buy

print(money)

Solution (Python):
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, AB):
    AB.sort()
    ans = 0

    for a, b in AB:
        if M > b:
            ans += a * b
            M -= b
        else:
            ans += a * M
            M -= M
            break

    return ans


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(N)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
for i in range(M):
    sumcost += A[0][0]
    A[0][1] -= 1
    if A[0][1] < 1:
        A.pop(0)

print(sumcost)

Solution (Python):

import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m >= M:
        break
    buy = min(M - m, plices[i][1])
    cost += plices[i][0] * buy
    m += buy
 
print(cost)

Solution (Python):
def main():
    N, M = map(int, input().split())
    D = [tuple(map(int, input().split())) for _ in range(N)]
    D.sort()
    ans = 0
    i = 0
    while M > 0:
        a, b = D[i]
        ans += a * min(M, b)
        M -= min(M, b)
        i += 1
    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()
use = 0
ans = 0
for i in range(n):
  use += AB[i][1]
  if use <= m:
    ans += AB[i][0]*AB[i][1]
  else:
    ans += AB[i][0]*(AB[i][1] - (use - m))
    break
print(ans)

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

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

cnt = M
re = 0
for i in range(N):
    A, B = price[i]
    if B < cnt:
        re += B * A
        cnt -= B
    else:
        re += cnt * A
        cnt = 0
        break
print(re)

Solution (Python):



"""
Energy Drink Collector
"""
test = False


def main():
    """
    とにかく安い方からM本になるまで買い続ける。
    """
    N, M = map(int, input().split())
    l = []
    bottle = 0
    cost = 0

    for _ in range(N):
        
        l.append(list(map(int, input().split())))

    
    l.sort()
    

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

    
    print(cost)


if __name__ == '__main__':
    main()

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

num = 0
price = 0
for s in S:
	if s[1] + num < M:
		price += s[0] * s[1]
		num += s[1]
	else:
		price += s[0] * (M - num)
		break
    
print(price)

Solution (Python):
N,M = map(int,input().split())
A = []
for i in range(N):
  key,value = map(int,input().split())
  dic = {"key":key,"value":value}
  A.append(dic)
sorted_A = sorted(A, key=lambda x:x['key'])
count = 1;
k = 0
for i in range(N):
  k += sorted_A[i].get("value")
  if k < M:
    count += 1
  else:
    break
result = 0
baught = 0
for i in range(count):
  baught += sorted_A[i].get("value")
  if baught < M:
    result += sorted_A[i].get("key") * sorted_A[i].get("value")
  else:
    result += sorted_A[i].get("key") * (sorted_A[i].get("value") - baught + M)
print(result)

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

data = [map(int,raw_input().split()) for i in xrange(N)]

data.sort()

cnt = 0
ans = 0
i = 0

while cnt < M:
    if data[i][1] + cnt < M:
        ans += data[i][1]*data[i][0]
        cnt += data[i][1]
    else:
        ans += data[i][0]*(M-cnt)
        break
    i += 1
print ans

Solution (Python):



import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
price_list = []

for _ in range(N):
    tmp = read_int()
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
price_list = list(set(price_list))
price_list.sort()

def solve():
    price = 0
    global M
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

Solution (Python):
N, M = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
P.sort()
ans = 0
for a, b in P:
    m = min(M, b)
    ans += a*m
    M -= m
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
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
b = 0
flag = 0
for i in range(n):
    while a[i][1]:
        a[i][1]-=1
        b+=1
        ans += a[i][0]
        if b ==m:
            flag=1
            break
    if flag==1:
        break
print(ans)

Solution (Python):

n, m = map(int, input().split())
data = [list(map(int, input().split())) for i in range(n)]
std_data = sorted(data)
j = 0
min_total = 0
bought_num = 0
while True:
    bought_num += std_data[j][1]
    min_total += std_data[j][0] * std_data[j][1]
    if bought_num >= m:
        min_total -= std_data[j][0] * (bought_num - m)
        break
    else:
        j += 1
print(min_total)

Solution (Python):
N,M = [int(x) for x in input().split(' ')]
AB = {}
for i in range(N):
  a,b = [int(x) for x in input().split(' ')]
  if a in AB:
    AB[a] += b
  else:
    AB[a] = b
    
dc = sorted(AB.items())

c = 0
m = M
for s in dc:
  price, stock = s
  if stock >= m:
    c += price * m
    break
  else:
    c += stock * price
    m -= stock
    
print(c)

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

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

AB = sorted(AB)

result = 0
c = M
for a, b in AB:
    t = min(c, b)
    c -= t
    result += a * t

print(result)

Solution (Python):



import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}


price_set = set()
for _ in range(N):
    tmp = read_int()
    
        
    price_set.add(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]

price_list = sorted(list(price_set))



def solve():
    price = 0
    global M
    
        
        
        
        
        
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

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

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

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

remaining_demand = M
payment = 0
for price, stock in stores:
    if stock >= remaining_demand:
        payment += price * remaining_demand
        break
    else:
        payment += price * stock
        remaining_demand -= stock

print("{}".format(payment))

Solution (Python):
def get_input_row():
  return [int(i) for i in input().split(" ")]
     
inp = get_input_row()
N = inp[0]
M = inp[1]
item_dict = {}
num = 0
for i in range(N):
  a, b = get_input_row()
  if a in item_dict:
    item_dict[a] += b
  else:
    item_dict[a] = b

sorted_list = [k for k in item_dict.keys()]
sorted_list.sort()
money = 0
for price in sorted_list:
  if M > item_dict[price]:
    M -= item_dict[price]
    money += price * item_dict[price]
  else:
    money += price * M
    break
print(money)

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

Solution (Python):
z=0;n,m,*l=map(int,open(0).read().split())
for s,t in sorted(zip(l[::2],l[1::2])):
  z+=s*min(m,t);m-=t
  if m<=0:print(z);break

Solution (Python):
import sys
n,m,*l=map(int,sys.stdin.read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m-=t
  if m<=0:
    print(ans)
    break

Solution (Python):
import sys
N,M = map(int,input().split())
List =[]
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    List.append([tmp_a,tmp_b])
List.sort()
sum_a,sum_b = 0,0
for i in range(N):
    if M-sum_b > List[i][1]:
        sum_a += List[i][0]*List[i][1]
        sum_b += List[i][1]
    else:
        sum_a += List[i][0]*(M-sum_b)
        sum_b += M-sum_b
        print(sum_a)
        sys.exit()

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

A_s = sorted(A_s,key=lambda x:x[0])
money = 0
num = 0
pre_num = 0
for a_s in A_s:
  num += a_s[1]
  if num <= M:
    money += a_s[1] * a_s[0]
    pre_num += a_s[1]
  else:
    money += (M-pre_num) * a_s[0]
    break
  
print(money)

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

Solution (Python):
N,M = map(int,input().split())
li = [list(map(int,input().split())) for i in range(N)]
li=sorted(li,key=lambda x: x[0])
m_sum=0
for i in li:
	buy=min(M,i[1])
	m_sum+=i[0]*buy
	M-=buy
print(m_sum)

Solution (Python):
n,m,*l=map(int,open(0).read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m-=t
  if m<=0:
    print(ans)
    break

Solution (Python):
n,m,*l=map(int,open(0).read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
  ans+=s*min(m,t)
  m=max(m-t,0)
  if not m:
    break
print(ans)

Solution (Python):
N,M = map(int,input().split())
li = [list(map(int,input().split())) for i in range(N)]
li=sorted(li,key=lambda x: x[0])
m_sum=0
for i in li:
	buy=min(M,i[1])
	m_sum+=i[0]*buy
	M-=buy
print(m_sum)

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

ans = 0

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

Solution (Python):
from operator import itemgetter
k, b = map(int, input().split())
a=[]
from heapq import heappush, heappop
for i in range(k):
    ta,tb = map(int, input().split())
    a.append([ta,tb])
a = sorted(a, key=itemgetter(0), reverse=False)
s=0
t = 0
ans = 0
i = 0
while s<b:
    s+=1
    if t<a[i][1]:
        ans+=a[i][0]
        t+=1
    else:
        i+=1
        ans+=a[i][0]
        t=1    

print(ans)

Solution (Python):
if __name__ == '__main__':
    n, m = map(int, input().split())
    l = sorted(tuple(int(s) for s in input().split()) for _ in range(n))
    ans = 0
    for a, b in l:
        if m == 0:
            break
        ans += min(m, b) * a
        m = max(m - b, 0)
    print(ans)

Solution (Python):


ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input().rstrip() 

n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])
 
rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

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

shop_list = [None] * N
for n in range(N):
    a, b = map(int, input().split())
    shop_list[n] = [a, b]

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

Solution (Python):


import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  
 
n, m = na()
ab = []
for i in range(n):
    ab.append(na())
ab.sort(key=lambda x: x[0])
 
rem = m
ans = 0
for v in ab:
    buy = min(rem, v[1])
    ans += buy * v[0]
    rem -= buy
print(ans)

Solution (Python):
[n,m] = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    [ai,bi] = [int(i) for i in input().split()]
    if ai in dic.keys():
        dic[ai] += bi
    else:
        dic[ai] = bi
sum = 0
ls = sorted(list(dic.keys()))
while m > 0:
    for i in range(len(ls)):
    
        if dic[ls[i]] >= m:
            sum += ls[i] * m
            m = 0
            break
        else:
            sum += dic[ls[i]]*ls[i]
            m -= dic[ls[i]]
print(sum)

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

shops = sorted(
    ab,
    key=lambda x: x[0]
)
paid = 0
for cost, stock in shops:
    num = min(m, stock)
    paid += num * cost
    m = m - num
    if m == 0:
        break
print(paid)

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

for i in range(N):
  L.append(list(map(int,input().split())))
  
L.sort(key=lambda x:x[0])
for l in L:
  if l[1]<=M:
    ans+=l[0]*l[1]
    M-=l[1]
  else:
    ans+=l[0]*M
    break

print(ans)

Solution (Python):
N,M=(int(i) for i in input().split())
L=sorted([[int(i) for i in input().split()] for i in range(N)])
ans=0
num=0
while M>0:
  if M>L[num][1]:
    M-=L[num][1]
    ans+=L[num][0]*L[num][1]
    num+=1
  else:
    ans+=L[num][0]*M
    M=0
print(ans)

Solution (Python):
n, m  = map(int, input().split())
arr = []
for i in range(n):
    a, b = map(int, input().split())
    arr.append([a, b])
arr.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    ans += arr[idx][0] * min(arr[idx][1], m)
    m -= min(arr[idx][1], m)
    idx += 1
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])
ab.append([0, 1])
i = 0
ans = 0
while m - ab[i][1] >= 0:
  ans += ab[i][0] * ab[i][1]
  m -= ab[i][1]
  i += 1
print(ans + ab[i][0] * m)

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

data.sort(key = lambda x: x[0])
left = m
i = 0
ans = 0
while left != 0:
    if data[i][1] <= left:
        ans += data[i][0] * data[i][1]
        left -= data[i][1]
    else:
        ans += data[i][0] * left
        left = 0
    i += 1
print(ans)

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

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

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

shop = []

ans = 0

num = 0

for i in range(N):
  shop.append(list(map(int, input().split())))
  
shop = sorted(shop)
  
for i in range(N):
  for b in range(shop[i][1]):
    if (num == M):
      break
    num += 1
    ans += shop[i][0]
    
print(ans)

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

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


a.sort()

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

Solution (Python):
s = input().split()
N = int(s[0])
M = int(s[1])
 
AB = {}
for i in range(N):
  data = input().split()
  if int(data[0]) in AB.keys():
    AB[int(data[0])] += int(data[1])
  else:
    AB[int(data[0])] = int(data[1])
AB = sorted(AB.items())
money = 0
num = 0
for A,B in AB:
  if num+B < M:
    money += A*B
    num += B
  elif num+B == M:
    money += A*B
    break
  elif num+B > M:
    money += A*(M-num)
    break
print(int(money))

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

AB = sorted(list(map(int,input().split())) for _ in range(N))
Money = 0
for A,B in AB:
    x = min(B,M)
    Money += A * x
    M -= x
print(Money)

Solution (Python):
s = input().split()
N = int(s[0])
M = int(s[1])
 
AB = {}
for i in range(N):
  data = input().split()
  if int(data[0]) in AB.keys():
    AB[int(data[0])] += int(data[1])
  else:
    AB[int(data[0])] = int(data[1])
AB = sorted(AB.items())
money = 0
num = 0
for A,B in AB:
  for b in range(B):
    num += 1
    money += A
    if num == M:
      break
      
  if num == M:
    break
  
print(int(money))

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

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

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

Solution (Python):
def c_energy_drink_collector(N, M, Drinks):
    drinks = sorted(Drinks)
    needs = M
    ans = 0
    for a, b in drinks:
        buy = min(needs, b)
        ans += a * buy
        needs -= buy
        if needs == 0:
            break
    return ans

N, M = [int(i) for i in input().split()]
Drinks = [[int(i) for i in input().split()] for j in range(N)]
print(c_energy_drink_collector(N, M, Drinks))

Solution (Python):
from sys import exit

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

shops = {}

for _ in range(N):
    A, B = map(int, input().split())
    if A in shops.keys():
        shops[A] += B
    else:
        shops[A] = B

shops = sorted(shops.items())
ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        break
    else:
        ans += k[0] * k[1]
        M -= k[1]

print(ans)

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

ans = 0
m = M
for x in xs:
    c = min(m, x[1])
    ans += x[0] * c
    m -= c
    if c == 0:
        break

print(ans)

Solution (Python):
N, M = map(int, input().split())
dic = {}
for i in range(N):
    A, B = map(int, input().split())
    if A in dic:
        dic[A] += B
    else:
        dic[A] = B
dic = sorted(dic.items())


sum = 0
for A, B in dic:
    if B < M:
        sum += A * B
        M -= B
    else:
        sum += A * M
        break

print(sum)

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

counter=0
amount=0
flag=0

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount)

Solution (Python):
N,M=map(int,input().split())
AB=[tuple(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])
money=0
for a,b in AB:
    if b>=M:
        money+=a*M
        break
    money+=a*b
    M-=b
print(money)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = []
for i in range(a):
    x, y = map(int, input().split())
    d.append((x, y))
d.sort()
count = 0
for i in range(a):
    if b <= d[i][1]:
        count += b * d[i][0]
        break
    else:
        b -= d[i][1]
        count += d[i][0] * d[i][1]
print(count)

Solution (Python):
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort()
x=0
z=0
y=b[1]
i=-1


while y>=0 and not LL==[]:
    i+=1
    if y<=LL[i][1]:
        print(x+LL[i][0]*y)
        break
    else:
        y-=LL[i][1]
        x+=LL[i][1]*LL[i][0]

Solution (Python):
n,m,*t=map(int,open(0).read().split());c=0
for a,b in sorted(zip(t[::2],t[1::2])):c+=a*min(m,b);m=max(0,m-b)
print(c)

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

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

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

yen_min = 0
for yen, honsu in sort_after:
    if M - honsu > 0:
        yen_min += yen * honsu
        M -= honsu
    else:
        yen_min += M * yen
        break

print(yen_min)

Solution (Python):
N, M = map(int, input().split())
ans = 0
drink = M
a, b = [], []
INF = float('inf')
for n in range(N):
    a.append(list(map(int, input().split())))
a.sort()
for i in a:
    if drink > i[1]:
        ans += i[0] * i[1]
        drink -= i[1]
    else:
        ans += i[0] * drink
        break
print(ans)

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

X = sorted(X, key = lambda x: x[0])
ans = 0
for i in range(N):
    if X[i][1] >= M:
        ans += M * X[i][0]
        break
    else:
        ans += X[i][1] * X[i][0]
        M -= X[i][1]

print(ans)

Solution (Python):
N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0
 
for i in range(N):
  price,honsu = map(int, input().split())
  if price in dic:
    dic[price] += honsu
  else:
    dic[price] = honsu
dic = sorted(dic.items())
for kakaku, number in dic:
    nokori = M-count
    count += number
    if count >= M:
      goukei += nokori*kakaku
      break
    else:
      goukei += number*kakaku
print (goukei)

Solution (Python):
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort()
x=0
z=0
y=b[1]
i=-1
while y>=0 and not LL==[]:
    i+=1
    if y<=LL[i][1]:
        print(x+LL[i][0]*y)
        break
    else:
        y-=LL[i][1]
        x+=LL[i][1]*LL[i][0]

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

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

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

data.sort()
num = 0


    
for x in data:
    for xx in range(int(x[1])):
        M -= 1
        num += int(x[0])
        if(M == 0):
            break
    if(M == 0):
        break
print(num)

Solution (Python):
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  if a not in dic:
    dic[a] = b
  else:
    dic[a] += b
c = sorted(dic.keys())
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)