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

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

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

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

Solution (Python):


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

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

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

c = 0
ans = 0
i = 0
while c < m and i < n:
    a, b = shop[i]
    if c + b >= m:
        ans += (m - c) * a
        c += (m - c)
    else:
        ans += b * a
        c += b
    i += 1
print(ans)

Solution (Python):
from collections import deque
n, m = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
arr.sort()
arr = deque(arr)
ans = 0
while m > 0:
    shop = arr.popleft()
    if shop[1] < m:
        ans += shop[0] * shop[1]
        m -= shop[1]
    else:
        ans += shop[0] * m
        break
print(ans)

Solution (Python):
n, m = map(int, input().split())
P = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 0
for x, y in P:
	q = min(m, y)
	ans += x*q
	m -= q
	if m == 0:
		print(ans)
		exit()

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

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

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

for j in range(n):
    m -= l[j][1]
    money += l[j][0] * l[j][1]

    if m < 0:
        money -= l[j][0] * -m
        break

print(money)

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

store_list = {}
for _ in range(N):
  A, B = map(int, input().split())
  if A not in store_list:
    store_list[A] = 0
  store_list[A] += B
  
store_list = sorted(store_list.items(), key=lambda x:x[0])

ans = 0
for A,B in store_list:
  num = min(M, B)
  ans += A * num
  M -= num
  if M == 0:
    break

print(ans)

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

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

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

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

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

res = 0
cnt = 0
for a, b in AB:
    tmp = M - cnt
    if tmp <= b:
        res += a * tmp
        break
    res += a * b
    cnt += b

print(res)

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

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

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

d={}

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

    if A in d:
        d[A]+=B
    else:
        d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0

for i in range(len(l)):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)

Solution (Python):
n, m = map(int, input().split())
cost = [None] * n
for i in range(n):
    cost[i] = tuple(map(int, input().split()))
cost = sorted(cost)
x = 0
for a, b in cost:
    if m <= 0:
        break
    x += a * min(b, m)
    m -= b
print(x)

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

a.sort()  

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

print(ans)

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

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

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

print(ans)

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

    ans = 0
    for d in drink:
        if M <= d[1]:
            ans += d[0] * M
            print(ans)
            exit()
        else:
            ans += d[0] * d[1]
            M -= d[1]


if __name__ == "__main__":
    main()

Solution (Python):
n,m = map(int,input().split())
sortsecond = lambda val:val[0]
shop = [[0]*2 for i in range(n)]
for i in range(n):
    dum = list(map(int,input().split()))
    shop[i] = dum
shop.sort(key=sortsecond)
ans = 0
for i in range(n):
    if m < shop[i][1]:
        ans += m*shop[i][0]
        m = 0
    else:
        ans += shop[i][0]*shop[i][1]
        m -= shop[i][1]
    if m == 0:
        break
print(ans)

Solution (Python):
import sys
n,m =map(int,input().split())
ls =[list(map(int,input().split())) for _ in range(n)]
ls.sort()
i = 0
j = 0
while True:
    if m - ls[i][1] > 0:
        m = m - ls[i][1]
        j += ls[i][0]*ls[i][1]
        i += 1
    else:
        j += m*ls[i][0]
        print(j)
        sys.exit()

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

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


resolve()

Solution (Python):
n,m = map(int,input().split())
dict = {}
su = 0
kounyu = 0
 
for i in range(n):
  A,B = map(int,input().split())
  if A in dict:
    dict[A] += B  
  else:
    dict[A] = B
  

d = sorted(dict.items())
 
for i in range(10**99):
  if d[i][1] >= m - kounyu:
    print(su + d[i][0]*(m - kounyu))
    exit()
    
  kounyu += d[i][1]
  su += d[i][1]*d[i][0]

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

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

Solution (Python):



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

AB.sort()

drink = 0
ans = 0
for a, b in AB:
  num = min(m - drink, b)
  m -= num
  ans += a * num
  if m == 0:
    break

print(ans)

Solution (Python):
n,m=map(int,input().split())
A=[[0,0] for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    A[i][0]=a
    A[i][1]=b
tmp=0
ans=0
B=sorted(A,key=lambda x:x[0])
for i in range(n):
    if tmp+B[i][1]<m:
        ans+=B[i][1]*B[i][0]
        tmp+=B[i][1]
    elif tmp+B[i][1]>=m:
        s=m-tmp
        ans+=s*B[i][0]
        break
print(ans)

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

Solution (Python):
def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    ds = [tuple(map(int, input().split())) for _ in range(N)]
    ds.sort(key=itemgetter(0))

    ans = 0
    for a, b in ds:
        buy = min(M, b)
        M -= buy
        ans += a * buy
        if not M:
            break
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(n)], key = lambda x: (x[0],-x[1]))
ans = 0
for i in l:
    if m - i[1]>=0:
        ans+= i[0]*i[1]
        m-=i[1]
    else:
        ans+= i[0]*m
        break
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 y:y[0])
cnt=0
ans=0
for i in range(n):
    cnt+=A[i][1]
    if m<=cnt:
        over=cnt-m 
        ans+=(A[i][0]*A[i][1])-(over*A[i][0])
        break
    else:
        ans+=A[i][0]*A[i][1]
print(ans)

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()
ans = 0
cou = 0
for a,b in p:
    if cou + b < m:
        cou += b
        ans += a*b
    elif cou + b >= m:
        ans += a*(m-cou)
        break
print(ans)

Solution (Python):

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

stores = []
s_append = stores.append
for i in range(N):
    A, B = map(int, input().split())
    s_append(
        {
            "price": A,
            "stock": B
        }
    )
stores.sort(key=lambda x: x["price"])

money = 0
for drink in stores:
    if M <= drink["stock"]:
        money += drink["price"] * M
        break
    else:
        money += drink["price"] * drink["stock"]
        M -= drink["stock"]

print(money)

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

Solution (Python):
N, M = map(int, input().split())
Price = [tuple(map(int, input().split())) for _ in range(N)]
Price.sort()
ans = 0
for (a, b) in Price:
    if M >= b:
        ans += a * b
        M -= b
    else:
        ans += a * M
        M = 0
        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()

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

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

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

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

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

Solution (Python):
N, M = map(int, input().split())
shops = list(list(map(int, input().split())) for _ in range(N))
shops.sort()
ans = 0
for value, count in shops:
    tmp_M = max(M - count , 0)
    ans += (M - tmp_M) * value
    M = tmp_M
    if M == 0:
        break
print(ans)

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

Solution (Python):

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

total = 0
cnt = 0
for price,num in drink:
    if cnt == m:
        break
    if cnt + num <= m:
        cnt += num
        total += num * price
    else:
        nya = max(abs(m - (cnt)),0)
        
        
        cnt += nya
        total += nya * price
print(total)

Solution (Python):
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
money = 0
drink = 0
for a,b in ab:
  money += a*b
  drink += b
  if drink >= m:
    money -= (drink-m) * a
    break
print(money)

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

AB.sort()

ans = 0
M_tmp = M
for i, (Ai, Bi) in enumerate(AB):
    cnt = min(M_tmp, Bi)
    ans += Ai * cnt
    M_tmp -= cnt

print(ans)

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

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

Solution (Python):
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda t: t[0])
ans = 0

for A, B in AB:
    if M-B>=0:
        ans += A*B
        M -= B
    else:
        ans += A*M
        break

print(ans)

Solution (Python):
N, M, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)
A.sort()

ans = 0
for a, b in A:
    ans += a*min(b, M)
    M -= min(b, M)

    if M == 0:
        break
print(ans)

Solution (Python):
def main():
    n, m = map(int, input().split())
    info = []
    for _ in range(n):
        info.append(list(map(int, input().split())))
    info.sort(key=lambda x: x[0])
    answer = 0
    for a, b in info:
        if m <= 0:
            break
        answer += a * min(m, b)
        m -= min(m, b)
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,M = IL()

d = ILL(N)

d.sort(reverse=True)
cost = 0
while M:
  a,b = d.pop()
  if M>=b:
    M -= b
    cost += a*b
  else:
    cost += a*M
    M = 0
P(cost)

Solution (Python):
N, M = map(int, input().split())
shops = [tuple(map(int, input().split())) for _ in range(N)]
shops.sort()
cost = 0
for shop in shops:
    value, amount = shop
    if amount < M:
        cost += value * amount
        M -= amount
    else:
        cost += value * M
        break
print(cost)

Solution (Python):






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





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

cnt = 0
ans = 0
for idx,lst in enumerate(AB_s):

    c = lst[0]
    n = lst[1]
    if n <= M-cnt:
        ans += c*n
        cnt += n

    else:
        ans += c*(M-cnt)
        cnt += (M-cnt)

        break
print(ans)

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

cnt = 0
ans = 0
for ai, bi in ab:
    if cnt + bi <= m:
        ans += ai * bi
        cnt += bi
    elif cnt <= m:
        ans += ai * (m - cnt)
        break
print(ans)

Solution (Python):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ 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]
    elif ab[i][1]>=m:
        ans+=ab[i][0]*m
        break
print(ans)

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

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

c = 0
for i in range(n):
  for j in range(l[i][1]):
    c += l[i][0]
    m -= 1
    if m == 0:
      print(c)
      exit()

Solution (Python):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ 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]
    elif ab[i][1]>=m:
        ans+=ab[i][0]*m
        break
print(ans)

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


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

Solution (Python):
n , m = map(int , input().split())
ans = []
total = 0
for i in range(n):
  a = list(map(int , input().split()))
  ans.append(a)
ans = sorted(ans, key=lambda x:x[0])
j = 0
while m > 0:
  small = min(ans[j][1] , m)
  total += ans[j][0] * small
  m -= small
  j += 1
print(total)

Solution (Python):
N, M, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

A.sort()

ans = 0
for a, b in A:
    ans += a*min(b, M)
    M -= min(b, M)

    if M == 0:
        break
print(ans)

Solution (Python):
from collections import defaultdict

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

for _ in range(n):
    a, b = map(int, input().split())
    drinks[a] += b

ans = 0
sorted_drinks = sorted(drinks.items(), key=lambda x:x[0])

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

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0, 1))
ans = 0
for ab in AB:
  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())
AB = sorted([list(map(int, input().split())) for _ in range(N)])
ans = 0
res = 0
ind = 0

while (res < M):
    if M - res >= AB[ind][1]:
        ans += AB[ind][0] * AB[ind][1]
        res += AB[ind][1]
    else:
        ans += AB[ind][0] * (M - res)
        res += (M - res)
    ind += 1

print(ans)

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

heapq.heapify(ab)

sm = 0
for _ in range(n):
    a, b = heapq.heappop(ab)
    if m >= b:
        m -= b
        sm += a * b
    else:
        sm += a * m
        break

print(sm)

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=sorted(L)

ans=0
now=M
for l in L:
    a,b=l
    ans+=min(b, now)*a
    now-=b
    if now<=0:
        break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

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

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


nokori = M
yen = 0
mise = 0
while nokori > 0:
  if A[mise][1] >= nokori: 
    yen += A[mise][0]*nokori
    break
  else:
    yen += A[mise][0]*A[mise][1]
    nokori -= A[mise][1]
    mise += 1
print(yen)

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

ans = 0
count = 0
for ab in AB:
    if count == M: break
    if M - count >= ab[1]:
        ans += ab[0] * ab[1]
        count += ab[1]
    else:
        ans += ab[0] * (M - count)
        count += (M - count)

print(ans)

Solution (Python):
n,m=map(int,input().split())
ab=[]
ans=0
for i in range(n):
  a,b=map(int,input().split())
  ab.append([a,b])
ab.sort()
for a,b in ab:
  t=min(b,m)
  ans+=t*a
  m-=t
print(ans)

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

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

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

ans = 0
need = M
for a, b in AB:
    buy = min(need, b)
    need -= buy
    ans += buy * a

print(ans)

Solution (Python):
def main():
    n,m = map(int,input().split())
    ab = sorted([list(map(int,input().split())) for _ in range(n)], key=lambda x:(x[0],x[1]))
    res = 0
    for a,b in ab:
        if m == 0:
            break
        buy = min(m,b)
        res += a*buy
        m -= buy
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,m = iim()
l =[]
for _ in range(n):
    l.append(iil())

l.sort()

num = 0
val = 0
for item in l:
    cst = item[0]
    cnt = item[1]
    if num + cnt < m:
        val += cst*cnt
        num += cnt
    else:
        val += cst*(m-num)
        break
print(val)

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

Solution (Python):
def resolve():
  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
  for ab in arr:
    if ab[1] >= m:
      ans += m * ab[0]
      break
    else:
      ans += ab[0] * ab[1]
      m -= ab[1]
  print(ans)

  return

if __name__ == "__main__":
  resolve()

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

Solution (Python):
a,b,c,d=list(map(int,input().split())),[],0,0
for i in range(a[0]):
    b.append(list(map(int,input().split())))
b.sort()
for i in range(a[1]):
    c+=b[d][0]
    b[d][1]-=1
    if b[d][1]==0:
        d+=1
print(c)

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

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

li.sort()

point = 0
yen = 0

for i in li:
    x,y = i
    if y + point >= m:
        yen += x*(m-point)
        break
    else:
        yen += x*y
        point += y

print(yen)

Solution (Python):
def main():
    n, m = map(int, input().split())
    info = []
    for _ in range(n):
        info.append(list(map(int, input().split())))
    info.sort(key=lambda x: x[0])
    answer = 0
    for a, b in info:
        if m <= 0:
            break
        answer += a * min(b, m)
        m -= min(b, m)
    print(answer)


if __name__ == '__main__':
    main()

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

drinks = []

for i in range(n):
  drinks.append(tuple(map(int,input().split())))
  
drinks = sorted(drinks)

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

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

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])
cst=0
for t in range(N):
    if a[t][1]>=M:
        cst+=(M*a[t][0])
        break
    else:
        cst+=(a[t][1]*a[t][0])
        M-=a[t][1]
print(cst)

Solution (Python):
import sys

N, M = map(int, sys.stdin.readline().split())
AB = sorted([list(map(int, sys.stdin.readline().split())) for _ in range(N)])

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

print(ans)

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

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

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

S = 0
num = 0
n1 = 0
n2 = 0
while num < M:
  if n2 == C[n1][1]:
    n1 += 1
    n2 = 0
  S += C[n1][0]
  num += 1
  n2 += 1
 
print(S)

Solution (Python):
N, M = map(int, input().split(' '))
drinks = sorted(tuple(tuple(map(int, input().split(' '))) for _ in range(N)))

cost = 0
for price, n in drinks:
    n = min(n, M)
    cost += n * price
    M -= n
    if M == 0:
        break

print(cost)

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

ls.sort()
ans = 0
numOfDrink = 0
for (a, b) in ls:
    if numOfDrink + b <= m:
        ans += a * b
        numOfDrink += b
    else:
        ans += a * (m-numOfDrink)
        break

print(ans)

Solution (Python):
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))

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

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

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

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

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

print(ans)

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

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

cnt, ans = 0, 0
for i in range(n):
    if m <= cnt + drinks[i][1]:
        num = m - cnt
        ans += drinks[i][0] * num
        break
    
    cnt += drinks[i][1]
    ans += drinks[i][0] * drinks[i][1]

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

ans = 0
cnt = 0

for ab in AB:
    for b in range(ab[1]):
        ans += ab[0]
        cnt += 1
        if cnt==M:
            break
    if cnt==M:
        break

print(ans)