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 numpy as np
n, m = list(map(int, input().split()))
ans = 0
pair = []
for i in range(n):
    pair.append(list(map(int, input().split())))

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

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

AB = sorted(AB)

money = 0
for i in range(N):
    m = min(AB[i][1], M)
    money += AB[i][0]*m
    M = M - m
    if M == 0:
        break

print(money)

Solution (Python):
n,m = list(map(int, input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
a.sort()
count = 0
kin = 0
ban = 0
while count < m :
    if a[ban][1] != 0 :
        count += 1
        kin += a[ban][0]
        a[ban][1] -= 1
    else :
        ban += 1
print(kin)

Solution (Python):
import numpy as np

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

AB = [ list(map(int, input().split())) for _ in range(N) ]
AB = np.array(AB)
AB = AB[AB[:,0].argsort(), :]

m = 0
s = 0
for n in range(N):
    s += AB[n][0]*AB[n][1]
    m += AB[n][1]
    if m>=M:
        s -= AB[n][0]*(m-M)
        break
print(s)

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

Solution (Python):



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

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

AB = [[A[i], B[i]] for i in range(N)]

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

yen = 0
head = 0
temp_M = M
while(True):
    nokori = AB[head][1]
    for i in range(temp_M):
        yen += AB[head][0]
        temp_M -= 1
        nokori -= 1
        if nokori == 0:
            break
    head += 1
    if temp_M ==0:
        break
print(yen)

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

abss.sort()
sum = 0
for (a,b) in abss:
    if m > b:
        sum = sum + a*b
        m = m-b
    else:
        sum = sum + a*m
        break

print(sum)

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

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

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

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

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

import numpy as np
inds = np.argsort(A)
ans = 0
rem = M
i = 0
while rem > 0:
    num = min(B[inds[i]], rem)
    ans += A[inds[i]] * num
    rem -= num
    i += 1

print(ans)

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

p = 0
for a, b in S:
  if M <= b:
    
    p += a * M
    break
  else:
    
    p += a * b
    M -= b
print(p)

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

ab_sort = sorted(ab, key=lambda x: x[0])
ans = 0
num = 0

for a, b in ab_sort:
    if num + b >= M:
        ans += (M - num) * a
        break
    else:
        num += b
        ans += a * b
print(ans)

Solution (Python):




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

for idx in range(n):
    ab.append(list(map(int,input().split())))

ab.sort()

bottle = 0
sum = 0
for idx in range(n):
    if bottle + ab[idx][1] >= m:
        sum += ab[idx][0] * (m - bottle)
        break
    else:
        sum += ab[idx][0] * ab[idx][1]
        bottle += ab[idx][1]
    

print(sum)

Solution (Python):
n,m=map(int,input().split())
p=[]
for i in range(n):
  a,b=map(int,input().split())
  p.append((a,b))
  
p.sort(key=lambda x:x[0])
remain = m
res=0

for t in p:
  c=min(remain,t[1])
  res+=t[0]*c
  remain-=c
  if remain==0:
    break
print(res)

Solution (Python):
N, M = map(int, input().split())
cost = 0
for A, B in sorted((tuple(map(int, input().split())) for i in range(N)), key=lambda p: p[0]):
	bought = min(M, B)
	cost += A * bought
	M -= bought

print(cost)

Solution (Python):
from sys import stdin

n, m = map(int, raw_input().strip().split())
inp = stdin.readlines()

p = [[0, 0] for i in xrange(n)]
i = 0
for line in inp:
    p[i] = map(int, line.strip().split())
    i += 1

p.sort()

pay = 0
rem = m
for i in xrange(n):
    a, b = p[i]
    tob = min(b, rem)
    rem -= tob
    pay += (a * tob)

    if rem <= 0: break

print pay

Solution (Python):
N, M = [int(s) for s in input().split(' ')]
stores = []
for i in range(N):
    stores.append(tuple([int(s) for s in input().split(' ')]))
stores = sorted(stores, key=lambda s: s[0])
N_buy = 0
money = 0
for store in stores:
    if N_buy + store[1] < M:
        N_buy += store[1]
        money += store[1] * store[0]
    else:
        money += (M - N_buy) * store[0]
        break
print(money)

Solution (Python):
import numpy as np

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

A = []
B = []
for i in range(N):
    tmp = [int(i) for i in input().split()]
    A.append(tmp[0])
    B.append(tmp[1])

idx = np.argsort(A)
A = np.array(A)[idx]
B = np.array(B)[idx]

buy_cnt = 0
cost = 0
for m in range(N):
    buy = B[m]
    if buy_cnt + buy > M:
        buy = M - buy_cnt
    
    buy_cnt += buy
    cost += buy*A[m]

    if buy_cnt == M:
        break

print(cost)

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

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

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

ans = 0
for ab in AB:
    a, b = ab
    c = min(M, b)
    ans += c*a
    M -= c
    if M == 0:
        break

print(ans)

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

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

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

for _ in [0]*n:
  a,b = map(int,input().split())
  if a in d.keys():
    d[a] = d[a] + b
  else:
    d[a] = b

l = list(d.keys())

l.sort()
s = 0

for t in l:
  if d[t] < m:
    m -= d[t]
    s += t*d[t]
  else:
    s += t*m
    break
print(s)

Solution (Python):



N, M = map(int, input().split(" "))
A = {}
B = {}

for i in range(N):
    a, b = map(int, input().split(" "))
    A[i] = a
    B[i] = b

cost = 0
for k, v in sorted(A.items(), key=lambda x: x[1]):
    if M - B[k] > 0:
        M -= B[k]
        cost += v * B[k]
    else:
        cost += v * M
        break

print(cost)

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
AB=[[0]*2 for i in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=MAP()

AB.sort()
sm=0
cnt=0
for i in range(N):
    a,b=AB[i]
    if cnt+b<=M:
        cnt+=b
        sm+=a*b
    else:
        sm+=a*(M-cnt)
        cnt=M
    if cnt==M:
        break
print(sm)

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

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

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,m=IL()
c=[IL() for i in range(n)]
c.sort()
cnt=0
ans=0
for i in range(n):
    if cnt+c[i][1]>=m:
        ans+=(m-cnt)*c[i][0]
        break
    else:
        cnt+=c[i][1]
        ans+=c[i][0]*c[i][1]
print(ans)

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

arr.sort()
ans = 0
for i, j in arr:
    for k in range(j):
        if m > 0:
            ans += i
            m -= 1
        else:
            break
print(ans)

Solution (Python):
N, M = map(int, input().split())
a = [0 for i in range(N)]
for i in range(N):
    A, B = map(int, input().split())
    a[i] = [A,B]
a.sort(key=lambda x:x[0])
cur = 0
ans = 0
for i in range(N):
    if cur+a[i][1]>= M:
        ans += a[i][0] * (M-cur)
        break
    else:
        ans += a[i][0] * a[i][1]
        cur += a[i][1]
print(ans)

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

AB = sorted(AB)

drink = 0
money = 0
iter = 0
while drink < M:
    add = min(AB[iter][1], M-drink)
    drink += add
    money += add*AB[iter][0]
    iter += 1

print(money)

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

new_AB = sorted(AB, key=lambda x: x[0])
m = M
i = 0
cost = 0
while m > 0:
    item = new_AB[i][1]
    if item >= m:
        buy_count = m
    else:
        buy_count = item
    m -= buy_count
    cost += buy_count * new_AB[i][0]
    
    i += 1

print(cost)

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

data.sort()

price = 0
for d in data:
    price += d[0] * min(M, d[1])
    M -= d[1]
    if M <= 0:
        break
print(price)

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

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, b = map(int, input().split())
    A[i] = a
    B[i] = b 
index = np.argsort(A)
A = A[index]
B = B[index]

m = 0
n = 0
ans = 0
while m != M:
    hon = B[n]
    yen = A[n]
    if M - m - hon >= 0:
        m += hon
        ans += yen * hon
        n += 1
    else:
        ans += yen * (M - m)
        break
print(int(ans))

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

A.sort()

res,count=0,0
for i in range(N):
    res+=A[i][0]*A[i][1]
    count+=A[i][1]
    if(count==M):
        break 
    if(count>M):
        res-=A[i][0]*A[i][1]
        count-=A[i][1]
        for j in range(1,A[i][1]+1):
            res+=A[i][0]
            count+=1
            if(count==M):
                print(res)
                exit()

print(res)
exit()

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 = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N)]
AB = sorted(AB, key=lambda x: x[0])
ans = 0
for a, b in AB:
    if M < b:
        ans += a*M
        break
    else:
        ans += a*b
        M -= b
print(ans)

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

i=0
sum1=0
while M>0:
    d=min(M,D[i][1])
    sum1+=D[i][0]*d
    M=M-d
    i=i+1
print(sum1)

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

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

line.sort()
ans = 0
for l in line:
    if M == 0:
        break
    a = l[0]
    b = l[1]
    if b<=M:
        ans += a*b
        M -= b
    else:
        ans += a*M
        break
print(ans)

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

total = 0
sp = []
for i in range(N):
    a, b = (int(i) for i in input().split())
    sp.append((a,b)) 

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


for sh in sp:    
    if M >= sh[1]:
        total += sh[0] * sh[1]
        M = M - sh[1]
    else:
        total += sh[0] * M
        M = 0
    if M == 0:
        break
print(total)

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

    A = []; B = []; i = 0
    while i < N:
        a, b = map(int, input().split(' '))
        A.append(a); B.append(b)
        i += 1
    
    A, B = zip(*sorted(zip(A, B)))
    
    count = M; money = 0
    for a, b in zip(A, B):
        while b:
            if count == 0:
                break
            count -= 1
            money += a
            b -= 1
    
    print(money)


if __name__ == '__main__':
    main()

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

a = [0 for k in range(n)]
b = [0 for k in range(n)]

for i in range(n):
    tempA, tempB = map(int, input().split())
    a[i] = tempA
    b[i] = tempB

t = sorted(range(len(a)), key=lambda k: a[k])

cost = 0
nokori = m
for i in t:
    if(b[i]<=nokori):
        cost += a[i]*b[i]
        nokori = nokori - b[i]
    else:
        cost += a[i]*nokori
        nokori = 0
    if(nokori==0):
        break

print(cost)

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

Solution (Python):
from sys import stdin

def main():
    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

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

input = lambda: stdin.readline()
main()

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

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

Solution (Python):
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
ab = [IL() for i in range(N)]

ab.sort()

cnt = 0
ans = 0
for a,b in ab:
    while b>0:
        ans += a
        M -= 1
        b -= 1
        if M == 0:
            break
    if M==0:
        break

print(ans)

Solution (Python):
import sys
sy=sys.stdin.readline
n,m=map(int,sy().split())
ab=[list(map(int,sy().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
ans,count=0,0
for i in ab:
    if count+i[1]<m:
        count+=i[1]
        ans+=i[0]*i[1]
    else:
        ans+=i[0]*(m-count)
        break
print(ans)

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

while m > 0:
    money += list[i][0]
    m -= 1
    list[i][1] -= 1
    if list[i][1] == 0:
        i += 1

print(money)

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

A_B.sort(key=lambda x: x[0])
count = 0
result = 0
for a, b in A_B:
    if count + b < M:
        count += b
        result += a * b
    else:
        result += a * (M - count)
        break

print(result)

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

A.sort()

res,count=0,0
for i in range(N):
    res+=A[i][0]*A[i][1]
    count+=A[i][1]
    if(count==M):
        break 
    if(count>M):
        res-=A[i][0]*A[i][1]
        count-=A[i][1]
        for j in range(1,A[i][1]+1):
            res+=A[i][0]
            count+=1
            if(count==M):
                print(res)
                exit()

print(res)
exit()

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):
n,m=map(int,input().split())
hoge=[]
for i in range(n):
  huga=list(map(int,input().split()))
  hoge.append(huga)
  
hoge.sort()

ans=0

mise=0

while 1:
  if(m==0):
    break
  
  if(hoge[mise][1]==0):
    mise+=1
  if(hoge[mise][1]>0):
    hoge[mise][1]-=1
    ans+=hoge[mise][0]
    m-=1
    
print(ans)

Solution (Python):
def main():
    N, M = map(int, input().split())
    shops = []
    for _ in range(N):
        A, B = map(int, input().split())
        shops.append((A, B))
    

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

    price = 0
    remains = M
    for shop in shops:
        price += shop[0] * min(shop[1], remains)
        remains -= shop[1]
        if remains <= 0:
            break
    print(price)

main()

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

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

L.sort()

tmp = 0
num = 0
for i in range(N):
    if num +  L[i][1] <= M:
        tmp += L[i][0] * L[i][1]
        num += L[i][1] 
    else:
        tmp += (M - num) * L[i][0]
        num = M
        
    if num == M:
        break


print(tmp)

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

ab.sort()
count = 0
summ = 0
for i in range(n):
    if count + ab[i][1] >= m:
        buy = m - count
        summ += ab[i][0] * buy
        print(summ)
        exit()
    else:
        count += ab[i][1]
        summ += ab[i][0] * ab[i][1]

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

for _ in range(N):
    a, b = map(int, input().split())
    juice_list.append((a, b))

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

juice_num = 0
money = 0
for juice in juice_list:
    if juice_num + juice[1] < M:
        money += juice[0] * juice[1]
        juice_num += juice[1]
    else:
        money += (M - juice_num) * juice[0]
        juice_num += M - juice_num
        break

print(money)

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

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

shops.sort()

result = 0
rest_count = M
for shop in shops:
    if rest_count > shop[1]:
        result += shop[0] * shop[1]
        rest_count -= shop[1]
    else:
        result += shop[0] * rest_count
        break

print(result)

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

at_n_hon = m
money = 0
for AB in ABs:
    kau_hon = AB[1] if AB[1] <= at_n_hon else at_n_hon
    at_n_hon -= kau_hon
    money += kau_hon *AB[0]
    if at_n_hon == 0:
        break

print(money)

Solution (Python):
N,M = map(int,input().split())
d = {}
for _ in range(N):
    a,b = map(int,input().split())
    if a in d.keys():
        d[a] += b
    else:
        d[a] = b

count = M
ans = 0
for i in sorted(list(d.keys())):
    if d[i] < count:
        count -= d[i]
        ans += i*d[i]
    else:
        ans += i*count
        break

print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


N, M = LI()

AB = []
for i in range(N):
    a,b = LI()
    AB.append([a, b])




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



count = 0
idx = 0
cost = 0
while count < M:
    
    if AB[idx][1] > M - count:
        
        cost += (M-count)*AB[idx][0]
        count = M
        break
    else:
        
        cost += AB[idx][0] * AB[idx][1]
        count += AB[idx][1]
    idx += 1

print(cost)

Solution (Python):
n, m = map(int, input().split())
shop = []
for i in range(n):
  shop.append(list(map(int, input().split())))
shop.sort()
bought = 0
cost = 0
for i in range(n):
  bought += min(m, shop[i][1])
  cost += min(m, shop[i][1]) * shop[i][0]
  m -= min(m, shop[i][1])
print(cost)

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

A = [[0,0] for i in range(N)]
B = [0 for j in range(N)]

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

A.sort()

money = 0
for i in range(N+1):
    if M > A[i][1]:
        M -= A[i][1]
        money += A[i][0] * A[i][1]
    else:
        for j in range(A[i][1]+1):
            if M <= j:
                money += A[i][0] * j
                print(money)
                exit()

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

Solution (Python):
N, M = map(int, input().split())
mise = [[int(x) for x in input().split()] for y in range(N)]
mise.sort()
m = 0
ans = 0
for val, hon in mise:
    zan = M - m
    if zan <= 0:
        break

    if zan > hon:
        m += hon
        ans += val * hon
    else:
        m += zan
        ans += zan * val

print(ans)

Solution (Python):

n, m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]
ab.sort(key=lambda x: x[0])
index = 0
ans = 0
while m > 0 and index <= n:
    if ab[index][1] <= m:
        ans += ab[index][0] * ab[index][1]
        m -= ab[index][1]
    else:
        ans += ab[index][0] * m
        m = 0
    index += 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 a:a[0] )

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


print(cost)

Solution (Python):
N,M = map(int,input().split(' '))
D = []
for i in [0]*N:
	a,b = map(int,input().split(' '))
	D.append([a,b])

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

ans = 0
for c, s in D:
	if s < M:
		M -= s
		ans += c * s
	else:
		ans += M * c
		break
print(ans)

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

from operator import itemgetter
ab.sort(key=itemgetter(0))  

i=0
p=0
ans=0
while p==0:
    if m>ab[i][1]:
        ans+=ab[i][1]*ab[i][0]
        m-=ab[i][1]
        i+=1
    else:
        ans+=ab[i][0]*m
        p=1

print(ans)

Solution (Python):
from operator import itemgetter


N, M = [int(v) for v in input().split()]
pairs = []
for i in range(N):
    pairs.append([int(v) for v in input().split()])
pairs.sort(key=itemgetter(0))

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

    if cnt >= M:
        break

print(ans)

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

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

money = 0
buy_num = 0

while buy_num < M:
    store = AB.pop(0)
    if store[1] >= M - buy_num:
        money = money + (M - buy_num) * store[0]
        buy_num = buy_num + (M - buy_num)
    else:
        money = money + store[1] * store[0]
        buy_num = buy_num + store[1]

print(money)

Solution (Python):
import numpy as np

n,m = list(map(int, input().split()))
a = []
b = []
for k in range(n):
    aa, bb = list(map(int, input().split()))
    a.append(aa)
    b.append(bb)


a = np.array(a)
b = np.array(b)

sort = np.argsort(a)

a_sorted = a[sort]
b_sorted = b[sort]

yen = 0
num = 0

for k in range(n):
    if num < m:
        if num + b_sorted[k] > m:
            num_buy = m - num
            yen += num_buy * a_sorted[k]
            num += num_buy
            break
        else:
            num += b_sorted[k]
            yen += b_sorted[k] * a_sorted[k]

    else:
        break
print(yen)

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

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

for n in range(0,N):
  i = input().split(" ")
  AB.append([int(i[0]),int(i[1])])


AB.sort()

nowBuy = 0
allcost = 0

for a in AB:
  cost = a[0]
  canBuy = a[1]
  if nowBuy + canBuy > M:
    allcost += cost*(M - nowBuy)
    break
  else:
    nowBuy += canBuy
    allcost += canBuy*cost

print(allcost)

Solution (Python):

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

for i in range(N):
    ab = tuple(map(int,input().split()))
    l.append(ab)
l.sort(key=lambda x:x[0])

res = 0
for t in l:
    if t[1] < M:
        res += t[0]*t[1]
        M -= t[1]
    elif t[1] >= M:
        res += t[0]*M
        break
print(res)

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

ab.sort()
ans = 0
for tab in ab:
    if m < 0:
        break
    ans += min(tab[1], m)* tab[0]
    m -= tab[1]
print(ans)

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

AB = [[int(v) for v in input().split()] for _ in range(N)]

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

index = 0
ans = 0 
count = 0
while True:
  a,b = AB[index]
  if count + b  >=  M:
    ans += (M-count) * a
    break
  else:
    count += b
    ans += a * b
    
  index += 1

print(ans)

Solution (Python):
import sys
import itertools
import copy

input = sys.stdin.readline
n, m = map(int, input().split())
drink = []
for _ in range(n):
    a, b = map(int, input().split())
    drink.append([a, b])
drink.sort()
ans = 0
for i in range(n):
    num = drink[i][1]
    if num <= m:
        ans += drink[i][0] * num
        m -= num
    else:
        ans += drink[i][0] * m
        m = 0
    if m == 0:
        break
print(ans)

Solution (Python):
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
d = {}
for i in range(N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if a not in d:
        d[a] = 0
    d[a] += b

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