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())
l=[]
for i in range(N):
    A,B=map(int,input().split())
    l.append([A,B])
l.sort()
left_drinks=M
prices=0
for i in l:
    if left_drinks<=0:
        break
    drinks = min(i[1],left_drinks)
    left_drinks -= drinks
    prices += i[0] * drinks
print(prices)

Solution (Python):
n,m = [int(x) for x in input().split()]
ab = []
for _ in range(n):
    a,b = [int(x) for x in input().split()]
    ab.append([a,b])

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

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

print(price)

Solution (Python):
n,m = map(int,input().split())
ab = sorted(list(map(int, input().split())) for i in range(n))
ans = stock = 0
for i in range(n):
    for j in range(ab[i][1]):
        ans +=ab[i][0]
        stock += 1
        if stock == m:
            print(ans)
            exit()

Solution (Python):
S = input().split(" ")
N = int(S[0])
M = int(S[1])

arr = []
for i in range(N):
    Q = input().split(" ")
    arr.append([int(q)for q in Q])

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

count = 0
total = 0
for a in arr:
    if count + a[1] <= M:
        total += a[0] * a[1]
        count += a[1]
    else:
        total += a[0] * (M - count)
        count += (M - count)
        break

print(total)

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

ls.sort()
drink = 0
money = 0
for i in ls:
    for j in range(i[1]):
        money += i[0]
        drink += 1
        if drink >= m:
            print(money)
            sys.exit()

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

s = sorted(L)
cnt=0
ans=0
while cnt<M:
  for i in range(N):
    if (M-cnt)<s[i][1]:
      ans+=(M-cnt)*s[i][0]
      cnt+=(M-cnt)
      
    else:
      ans+=s[i][0]*s[i][1]
      cnt+=s[i][1]
print(ans)

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

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

r = 0
kA = sorted(range(n), key=lambda k: A[k])
for i in range(n):
    r += A[kA[i]]*min(m, B[kA[i]])
    m -= B[kA[i]]
    if m <0:
        break
print(r)

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

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

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

ab = np.array(ab)
ab = sorted(ab, key = lambda x: x[0])

ch = m+0
ans = 0
ax = 0
while ch > 0:
    t_ab = ab[ax]
    if t_ab[1] <= ch:
        num = t_ab[1]
    else:
        num = ch
    ans += t_ab[0]*num
    ax += 1
    ch -= num

print(ans)

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

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

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

ans = 0
while m > 0:
    a, b = ab.pop(0)
    ans += min(m, b) * a
    m -= min(m, b)

print(ans)

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
import queue
import copy


def gcd(m,n):
  x = max(m,n)
  y = min(m,n)
  if x%y == 0:
    return y
  else:
    while x%y != 0:
      z = x%y
      x = y
      y = z
    else:
      return z


def bfs(SS, x, y, H, W):
  x_next = [0, 0, -1, 1]
  y_next = [1, -1, 0, 0]
  tempx = x
  tempy = y
  mlength = 0
  q = deque()
  xytuple = (x, y, 0)
  q.append(xytuple)


  while q:
    xytuple = q.popleft()
    SS[xytuple[0]][xytuple[1]] = "x" 
    for i in range(4): 
      tempx = xytuple[0] + x_next[i]
      tempy = xytuple[1] + y_next[i]
      
      
      if(0 <= tempx and tempx < H and 0 <= tempy and tempy < W and SS[tempx][tempy] == "."):
        temptuple = (tempx, tempy, xytuple[2]+1)
        SS[temptuple[0]][temptuple[1]] = "x" 
        mlength = max(mlength, xytuple[2] +1)
        q.append(temptuple)
      
  return mlength





NM = str(input()).split()
N = int(NM[0])
M = int(NM[1])
A = []
ans = 0

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


A.sort()


count = 0

while True:
  if (M==0):
    break
  if not(A[count][1] == 0):
    ans += A[count][0]
    A[count][1] -= 1
    M -= 1
  else:
    count+=1



print(ans)

Solution (Python):
N_ken, M_hon = map(int, input().split())
ab = []
yen = 0
hon = 0

for i in range(N_ken):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

ab.sort()

for a, b in ab:
    tmp = min(M_hon - hon, b)
    yen += tmp * a
    hon += tmp
    
    if (hon == M_hon):
        break

print(yen)

Solution (Python):
n,m=map(int,input().split())
ab=[]
for i in range(n):
    abi=list(map(int,input().split()))
    ab.append(abi)
ab.sort()
msum=0
asum=0
for i in range(n):
    ai,bi=ab[i]
    asum=asum+ai*bi
    msum=msum+bi  
    if msum>=m:
        break
asum=asum-ai*(msum-m)
print(asum)

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

p.sort(key=lambda x: x[0])
ans=0
for i in p:
    if i[1] >= m:
        ans += i[0] * m
    else:
        ans += i[0] * i[1]
    m -= i[1]

    if m <= 0:
        break
print(ans)

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

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

drink.sort()

x = 0
ans = 0
for a, b in drink:
   if (x + b <= m):
      ans += a * b
      x += b
   else:
      y = m - x
      ans += a * y
      break

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from operator import itemgetter

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N, M = MAP()
    AB = [LIST() for i in range(N)]
    L = sorted(AB, key=itemgetter(0))

    money = 0
    cnt = 0
    for i in range(N):
        for j in range(L[i][1]):
            money += L[i][0]
            cnt += 1
            if cnt == M:
                print(money)
                sys.exit()


if __name__ == '__main__':
    main()

Solution (Python):
f = lambda : map(int,input().split())
n,m = f()
ll = sorted([list(f()) for _ in range(n)])
ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())
n,m = f()
ll = sorted([list(f()) for _ in range(n)])

ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break

print(ans)

Solution (Python):
n,m = map(int,input().split())
ll = sorted([list(map(int,input().split())) for _ in range(n)])
ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
ll = sorted([list(map(int,input().split())) for _ in range(n)])

ans = 0
for p, c in ll:
  ans += p*min(m,c)
  m -= c
  if m < 1:
    break

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
ll = sorted([list(map(int,input().split())) for _ in range(n)])

ans = 0
cnt = 0
for l in ll:
  if cnt + l[1] > m:
    ans += (m-cnt)*l[0]
    break
  else:
    cnt += l[1]
    ans += l[0]*l[1]

print(ans)

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

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

AB = sorted(AB)

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

print(answer)

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

AB.sort()

ans=0

for ab in AB:
    if M==0:
        break
    if ab[1]<=M:
        M-=ab[1]
        ans+=ab[0]*ab[1]
    elif ab[1]>M:
        ans+=ab[0]*M
        M-=M

print(ans)

Solution (Python):
import numpy as np 

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

need = M
cost = 0

AB.sort()

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

print(cost)

Solution (Python):
N,M=map(int,input().split())
X=[[int(i) for i in input().split()] for i in range(N)]
X.sort()
t=M
ans=0
for a,b in X:
    if t>b:
        ans+=a*b
        t-=b
    else:
        ans+=a*t
        break
print(ans)

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

s = 0
c = 0
for i in range(N):
    s += D[i][1]
    c += D[i][0] * D[i][1]
    if s >= M:
        c -= (s - M) * D[i][0]
        break

print(c)

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

ab.sort()
res=0
for i in range(len(ab)):
    if ab[i][1] < m: 
        res+= (ab[i][0]*ab[i][1])
        m-= ab[i][1]
    else: 
        res+= ab[i][0]*m
        break

print(res)

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

ab.sort()

ans = 0
for _ab in ab:
    if m == 0:
        break

    if _ab[1] <= m:
        ans += _ab[0]*_ab[1]
        m -= _ab[1]
    elif _ab[1] > m:
        ans += _ab[0]*m
        m = 0

print(ans)

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

lis = sorted(lis, key = itemgetter(0))

money = 0
cnt = 0
for i in range(n):
    money += lis[i][0] * lis[i][1]
    cnt += lis[i][1]
    
    if cnt >= m:
        money -= (cnt-m) * lis[i][0]
        break
print(money)

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

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

Solution (Python):
def solve(n, m, AB):
    AB.sort()
    count, total = 0, 0
    for a, b in AB:
        if count + b >= m:
            total += a * (m - count)
            break
        else:
            count += b
            total += a * b
    return total

_n, _m = map(int, input().split())
_AB = [list(map(int, input().split())) for _ in range(_n)]
print(solve(_n, _m, _AB))

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

total_m, total_c = 0, 0
for money, count in a:
    if total_c + count >= M:
        total_m += (M-total_c)*money
        break
    total_m += count*money
    total_c += count
print(total_m)

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

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

AB = []

for _ in range(N):
    AB.append([int(i) for i in input().split()])

AB = sorted(AB)

money = 0

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

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

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

Solution (Python):
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = True

p = None
XY = None
N = None


def main():
    N, M = MI()
    AB = [None] * N

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

    AB = sorted(AB)

    ans = 0
    total = 0

    for i in range(N):
        price = AB[i][0]
        size = AB[i][1]

        if M < total + size:
            n = M - total
            ans += price * n
            total += n
        else:
            ans += price * size
            total += size

        if total >= M:
            break

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
from operator import itemgetter

n, m = map(int, input().split())
pair = []

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

pair = sorted(pair, key=itemgetter(0))

cnt = 0
ans = 0

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

print(ans)

Solution (Python):
n, m = map(int, input().split())
AB = []
for i in range(n):
    AB.append(list(map(int, input().split())))
AB = sorted(AB, key=lambda x:x[0])
ans = 0
cnt = 0 
for a, b in AB:
    pre_cnt = cnt
    cnt += b
    if cnt >= m:
        ans += a*(m-pre_cnt)
        break
    else:
        ans += a*b
print(ans)

Solution (Python):
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count, total, i = 0, 0, 0
while count < m:
    count += ll[i][1]
    total += ll[i][0]*ll[i][1]
    i += 1
total += ll[i-1][0]*(m-count)
print(total)

Solution (Python):
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count = 0
total = 0
for i in range(n):
    if count < m:
        count += ll[i][1]
        total += ll[i][0]*ll[i][1]
    else:
        c = count-m
        total -= ll[i-1][0]*c
        print(total)
        exit()
    if i == n-1:
        c = count-m
        total -= ll[i][0]*c
        print(total)
        exit()

Solution (Python):
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ll = sorted(l)
count = 0
total = 0
for i in range(n):
    if count < m:
        count += ll[i][1]
        total += ll[i][0]*ll[i][1]
    else:
        c = count-m
        total -= ll[i-1][0]*c
        print(total)
        exit()
    if i == n-1:
        d = m - count
        total += ll[i][0]*d
        print(total)
        exit()

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

d.sort()

tmp = m
ans = 0
for i in range(n):
    buy = min(tmp,d[i][1])
    tmp -= buy
    ans += buy*d[i][0]
    if not tmp:
        break

print(ans)

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

n, k = map(int, input().split())
arr = list(tuple(map(int, input().split())) for _ in range(n))
arr = sorted(arr, key=lambda x:x[0])
res = 0
for i in range(n):
    tk = min(k, arr[i][1])
    res += tk*arr[i][0]
    k -= tk
print(res)

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

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,M = cin.mapInt()
    A = cin.intListList(N)
    ans = 0
    A.sort()
    for i in range(N):
        b = min(M,A[i][1])
        ans += b * A[i][0]
        M-=b
    print(ans)
    return

if __name__ == "__main__":
    main()

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

AB.sort()

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

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

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

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

print(c)

Solution (Python):
from operator import itemgetter
n,m = map(int, input().split())
input_list = []
for _ in range(n):
    i,j = map(int, input().split())
    d = {'price': i, 'amount': j}
    input_list.append(d)

total = 0
target = m
sorted_list = sorted(input_list, key=itemgetter('price'))
for dic in sorted_list:
    price = dic['price']
    amount = dic['amount']
    if target <= amount:
        total += target*price
        break
    else:
        total += amount*price
        target -= amount
print(total)

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

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

AB.sort()

ans=0
cnt=0
for i in range(N):
    if cnt+AB[i][1]<M:
        cnt+=AB[i][1]
        ans+=AB[i][0]*AB[i][1]
    else:
        ans+=(M-cnt)*AB[i][0]
        break
        
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 A:A[0])
okane=0
remain=m
for i in range(n):
    if remain>0:
        if remain-AB[i][1]>0:
            okane+=AB[i][1]*AB[i][0]
            remain-=AB[i][1]
        else:
            okane+=remain*AB[i][0]
            remain=0
    else:
        break
print(okane)

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

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

ans = 0
for t in table:
  if m > t[1]:
    ans += t[1] * t[0]
    m -= t[1]
  else:
    ans += m * t[0]
    break
print(ans)

Solution (Python):
ab = []

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

drink = 0
money = 0

while True:
  for i in range(n):
    if ab[i][1] + drink >= m:
      money += ab[i][0] * (m - drink)
      print(money)
      exit()
    else:
      money += ab[i][0] * ab[i][1]
      drink += ab[i][1]

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

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 i in range(n):
	ans += ab[i][0] * min(ab[i][1], m - cnt)
	cnt += min(ab[i][1], m - cnt)
	if cnt == m:
		print(ans)
		exit()

Solution (Python):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
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):
def main():
    N, M = map(int, input().split(" "))
    prices = []
    for i in range(N):
        tmp = list(map(int, input().split(" ")))
        prices.append(tuple(tmp))
    prices.sort(key=lambda x: x[0])
    cost = 0
    for price in prices:
        if M < 0:
            break
        cost += price[0] * min(M, price[1])
        M = max(0, M - price[1])
    print(cost)


if __name__ == '__main__':
    main()

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()
buy_num=0
i=0
ans=0

for i in range(N):

    ai=AB[i][0]
    bi=AB[i][1]
    
    if M-buy_num>bi:
        buy_num+=bi
        ans+=ai*bi
            
    else:
        
        ans+=ai*(M-buy_num)
        break
        
print(ans)

Solution (Python):

import math
import heapq
import bisect
import numpy as np


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


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

A = sorted(A)

index = 0
ans = 0
while M>0:
    if M >= A[index][1]:
        ans += A[index][0]*A[index][1]
        M -= A[index][1]
    else:
        ans += A[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 x: x[0])
now_item = 0
money = 0

for e in AB:
    price = e[0]
    amount = e[1]
    if now_item + amount < M:
        now_item += amount
        money += price * amount
    else:
        money += price * (M - now_item)
        print(money)
        exit()

Solution (Python):
import sys


N, M = map(int, input().split())
S = [list(map(int, x.split())) for x in sys.stdin.readlines()]

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

amount = 0

for a, b in S:
    num = min(M, b)
    amount += a * num
    M -= num
    if M == 0:
        break

print(amount)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
 
def main():
    N, M = map(int, readline().split())
    d = map(int, read().split())
    AB = list(zip(d, d))
    AB = sorted(AB)
 
    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break
 
        else:
            price += x * y
            have += y
 
 
    print(price)
 
main()

Solution (Python):
import sys

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    cost = 0
    r = m
    for a, b in ab:
        if b <= r:
            cost += a * b
            r -= b
        else:
            cost += a * r
            break
    return cost

if __name__ == '__main__':
    ans = main()
    print(ans)

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

rest_necessary_num = M
necessary_money = 0
for pn in price_num:
    price, num = pn
    if rest_necessary_num >= num:
        
        necessary_money += price * num
        rest_necessary_num -= num
    else:
        
        necessary_money += price * rest_necessary_num
        break

print(necessary_money)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



def main():
    N, M = map(int, readline().split())
    d = map(int, read().split())
    AB = list(zip(d, d))
    AB = sorted(AB)

    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()

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

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

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

    AB = sorted(AB)

    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()

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

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

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

    AB = sorted(AB)

    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()

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

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

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

    AB = sorted(AB)

    have = 0
    price = 0
    while M != have:
        AB[0][1] -= 1
        price += AB[0][0]
        have += 1

        if AB[0][1] == 0:
            del AB[0]


    print(price)

main()

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

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

AB.sort()

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

Solution (Python):
n,m = map(int,input().split())
acc = 0
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))
for a,b in sorted(ab):
    c = min(b,m)
    m -= c
    acc += a * c    
    if m == 0:
        break
print(acc)

Solution (Python):
n,m = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0]))
c = 0
mony = 0
for i in a:
    if c + i[1] < m:
        c += i[1]
        mony += i[0]*i[1]
    else:
        for j in range(i[1]):
            c += 1
            mony += i[0]
            if c >= m:
                break
        break
print(mony)

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

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

stores = sorted(stores)
drinks = 0
price = 0
for s in stores:
    drinks += s[1]
    price += s[0] * s[1] 
    if drinks == M:
        break
    elif drinks > M:
        price -= (drinks - M) * s[0]
        break
        
print(price)

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

li.sort()

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

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

nw = 0
cst = 0
for i in range(n):
    memo = min(m,li[i][1])
    m-=memo
    cst += li[i][0]*memo
    if m==0:
        break
print(cst)

Solution (Python):
N, M = map(int, input().split())
AB = [[int(i) for i in input().split()]for j in range(N)]
sortsecond = lambda val: val[0]
AB.sort(key=sortsecond)
ans = 0
c = 0
for ab in AB:
    if c+ab[1] <= M:
        ans += (ab[0] *ab[1])
        c += ab[1]
        continue
    else:
        while c != M:
            c += 1
            ans += ab[0] 
        break

print(ans)

Solution (Python):

def main():
    N, M, *AB = map(int, open(0).read().split())
    AB = list(zip(*[iter(AB)] * 2))
    AB.sort()
    ans = 0
    for a, b in AB:
        while b > 0 and M > 0:
            ans += a
            b -= 1
            M -= 1
    print(ans)


if __name__ == "__main__":
    main()

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