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

def main():
	n, m =  map(int , input().split())
	ab = []
	for i in range(0 , n):
		ab.append(list(map(int , input().split())))
	ab.sort()
	ans = 0
	for i in range(0 , n):
		if (m-ab[i][1]>=0):
			m = m-ab[i][1]
			ans = ans+(ab[i][0]*ab[i][1])
		elif(m>0):
			ans = ans+(m*ab[i][0])
			m  = 0
	print(ans)
if __name__ =="__main__":
	main()

Solution (Python):

def main():
	n, m =  map(int , input().split())
	ab = []
	for i in range(0 , n):
		ab.append(list(map(int , input().split())))
	ab.sort()
	ans = 0
	for i in range(0 , n):
		if (m-ab[i][1]>=0):
			m = m-ab[i][1]
			ans = ans+(ab[i][0]*ab[i][1])
		elif(m>0):
			ans = ans+(m*ab[i][0])
			m  = 0
	print(ans)
if __name__ =="__main__":
	main()

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

c=sorted(c,key=lambda x:x[0])
ans=0
for i in range(a):
    if b==0:
        break
    elif b>=c[i][1]:
        b-=c[i][1]
        ans+=c[i][1]*c[i][0]
    else:
        ans+=b*c[i][0]
        break
print(ans)

Solution (Python):
n,m = map(int, input().split())
ab = []
for i in range(n):
    a,b = list(map(int, input().split()))
    ab.append((a,b))
ab.sort()
num = 0
money = 0
for h in range(n):
    num += ab[h][1]
    if num < m:
        money += ab[h][0]*ab[h][1]
    elif num == m:
        money += ab[h][0]*ab[h][1]
        break
    else:
        money += (ab[h][0]*ab[h][1] - (num-m)*ab[h][0])
        break
print(money)

Solution (Python):
n,m=map(int,input().split())
a=[]
for _ in range(n):
  b=list(map(int,input().split()))
  a.append(b)
  
a.sort(key=lambda x: x[0])
ans=0
h=0

for y in a:
  d=y[0]
  e=y[1]
  if h+e>m:
    ans+=(m-h)*d
    h+=(m-h)
  else:
    h+=e
    ans+=d*e

print(ans)

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

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

ab.sort()

p = 0
x = 0

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

print(p)

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

Solution (Python):
N, M = list(map(lambda n: int(n), input().split(" ")))
E = []
for i in range(N):
  tmp = input().split(" ")
  E.append({
    "price": int(tmp[0]),
    "count": int(tmp[1])
  })

E.sort(key=lambda e: e["price"])

totP = 0
totC = 0
for i in range(len(E)):
  if totC + E[i]["count"] >= M:
    totP += (M - totC) * E[i]["price"]
    break
  else:
    totC += E[i]["count"]
    totP += E[i]["price"] * E[i]["count"]

print(totP)

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=itemgetter(0))
ans = 0
for i in range(N):
    ans += min(M, AB[i][1]) * AB[i][0]
    M -= min(M, AB[i][1])
    if M==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()
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):
import numpy as np
n,m = map(int, input().split())
A = np.array([list(map(int, input().split())) for _ in range(n)], dtype='int64')
ind = np.argsort(A[:,0])
A = A[ind]
num = 0
money = 0
for a,b in A:
    num += b
    if num < m:
        money += a * b
    else:
        money += a * (b - (num - m))
        break
print(money)

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

for _ in range(N):
  A, B = map(int, input().split())
  AB.append((A, B))

AB.sort()

i = 0
ans = 0

while M > 0:
  A, B = AB[i]
  if B <= M:
    ans += A * B
    M -= B
  else:
    ans += A * M
    M = 0
  i += 1

print(ans)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,M = MI()
AB = [tuple(MI()) for _ in range(N)]
AB.sort()

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, M = LI()
    AB = [LI() 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
            break

    print(ans)

if __name__ == '__main__':
    resolve()

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

C={}
S1=[]
for i in range(n):
    a,b = map(int,input().split())
    S1.append(a)
    if a in C:
        C[a]+=b
    else:
        C[a]=b
S=list(set(S1))
S.sort()

ans=0
for s in S:
    
    if m<C[s] :
        ans+=m*s
        break
    else:
        ans+=C[s]*s
        m-=C[s]

print(ans)

Solution (Python):
import sys

input = sys.stdin.readline
n, m = map(int, input().split())
dict1 = {}
for _ in range(n):
    price, b = map(int, input().split())
    if price in dict1:
        dict1[price] += b
    else:
        dict1[price] = b

money_cnt = 0
for price, b in sorted(dict1.items()):
    if b < m:
        m -= b
        money_cnt += price * b
    else:
        money_cnt += price * m
        break
print(money_cnt)

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

ab=sorted(ab)
ans=0
d=m

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

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])
S = 0
for l in L:
  if l[1]>=M:
    S += l[0]*M
    break
  else:
    S += l[0]*l[1]
    M -= l[1]
print(S)

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
cnt = 0
cnt_money = 0
for i in sorted([rl() for _ in range(n)]):
  a, b = i
  if cnt + b < m:
    cnt += b
    cnt_money += a*b
  else:
    cnt_money += (m - cnt) * a
    break
print(cnt_money)

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

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

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

c = zip(A, B)
c = sorted(c)

A, B = zip(*c)

count = 0
money = 0
for i in range(N):
    count += B[i]
    money += A[i] * B[i]
    if count < M:
        continue
    else:
        while count != M:
            count -= 1
            money -= A[i]
        print(money)
        exit()

Solution (Python):

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

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

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

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

ret = 0
money = 0

for a, b in AB:
    if ret >= M:
        break

    while ret < M and b >= 1:
        b -= 1
        ret += 1
        money += a
        
print(money)

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

AB.sort()

money = 0

m = 0
for ab in AB:
    a = ab[0]
    b = ab[1]

    if m + b <= M:
        money += a * b
        m += b
    
    else:
        money += min(b, (M - m)) * a
        m += min(b, (M - m))

    if m == M:
        break

print(money)

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

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

Solution (Python):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, m = nm()
    AB = [tuple(map(int, input().split())) for _ in range(n)]
    AB = sorted(AB, key=lambda x: x[0])
    num = 0
    ans = 0
    for a, b in AB:
        w_num = m - num
        if w_num <= b:
            num += w_num
            ans += w_num * a
            break
        else:
            num += b
            ans += b * a
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0
x = 0

for t in d:
    if x+t[1] < m:
        ans += t[0]*t[1]
        x += t[1]
    else:
        ans += t[0]*(m-x)
        break

print (ans)

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

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

heapq.heapify(a_b)

res = 0
for i in range(m):
    tmp_a, tmp_b = heapq.heappop(a_b)
    res += tmp_a 
    tmp_b -= 1
    if tmp_b > 0:
        heapq.heappush(a_b, [tmp_a, tmp_b])

print(res)

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

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

a_b.sort()

res = 0
counter = 0
for i in range(n):
    counter = min(m, a_b[i][1])
    m -= counter
    res += counter * a_b[i][0]
    if m == 0:
        break
print(res)

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

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

money = 0
cnt = 0
for a, b in sorted_AB:
    tmp = min(b, M - cnt)
    cnt += tmp
    money += a * tmp
    if cnt == M:
        break
print(money)

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

Solution (Python):
n,m = map(int,input().split())
a_b = {}
for i in range(n):
    x,y = map(int,input().split())
    if x in a_b.keys():
        a_b[x] += y
        continue
    a_b[x] = y
a_b = sorted(a_b.items(), key=lambda x:x[0])


c = 0
ans = 0
t = 0
for i in range(int(len(a_b))):
    c += a_b[i][1]
    if c > m:
        ans += a_b[i][0] * (m - t)
        break
    else:
        ans += a_b[i][0] * a_b[i][1]
        t += a_b[i][1]

print(ans)

Solution (Python):
f=lambda:[*map(int,input().split())]
n,m=f()
c=0
for a,b in sorted((f()) for _ in range(n)):
  t=min(b,m)
  c+=a*t
  m-=t
print(c)

Solution (Python):
f=lambda:[*map(int,input().split())]
n,m=f()
p=sorted((f()) for _ in range(n))
c=0
for a,b in p:
  if m>b:
    c+=a*b
    m-=b
  else:
    c+=a*m
    break
print(c)

Solution (Python):
n,m=map(int,input().split())
d={}
A=[0]*n
B=[0]*n
for i in range(n):
    A[i],B[i]=map(int,input().split())
    d[str(i)]=A[i]
a=sorted(d.items(),key=lambda x:x[1])
ans=0
for i in range(n):
    if m>B[int(a[i][0])]:
        m-=B[int(a[i][0])]
        ans+=a[i][1]*B[int(a[i][0])]
    else:
        ans+=a[i][1]*m
        break
print(ans)

Solution (Python):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for i in range(n)])
shop,cost,rest=0,0,m
while True:
    if ab[shop][1]<rest:
        cost += ab[shop][1]*ab[shop][0]
        rest -= ab[shop][1]
        shop+=1
    else:
        cost+=ab[shop][0]*rest
        break
print(cost)

Solution (Python):
import sys

N, M = map(int, sys.stdin.readline().split())

shops = []
for _ in range(N):
    a, b = map(int, sys.stdin.readline().split())
    shops.append((a, b))

ans = 0
num = 0
for a, b in sorted(shops):
    if num < M:
        if num + b < M:
            num += b
            ans += a * b
        else:
            ans += a * (M - num)
            break

print(ans)

Solution (Python):
store_num,bottle_num = map(int,input().split())

drink_dict = {}

for i in range(store_num):
    pay,num = map(int,input().split())
    drink_dict.setdefault(pay,0)
    drink_dict[pay] += num
    

drink_sorted = sorted(drink_dict.items(),key=lambda x:x[0])


cost = 0

for i in range(store_num):
    value = drink_sorted[i][0]
    num = drink_sorted[i][1]
    cost += value * min(num,bottle_num)
    bottle_num -= num
    
    if bottle_num <= 0:
        print(cost)
        break

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

Solution (Python):
n,m=map(int,input().split())
d={};price=0
for _ in range(n):
  a,b=map(int,input().split())
  if a not in d:
    d[a] = b
  else:
    d[a] += b
d=sorted(d.items(),key=lambda x:x[0])
for i in d:
  for _ in range(i[1]):
    if m == 0:
      print(price)
      exit()
    m-=1
    price+=i[0]
else:
  print(price)

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

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

a = sorted(d.items(), key=lambda x:x[1])
ans=0

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

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

Solution (Python):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l)
drink=0
money=0
index=0
while(drink<m):
    if l[index][1]+drink<m:
        drink+=l[index][1]
        money+=l[index][0]*l[index][1]
        index+=1
    else:
        money+=l[index][0]*(m-drink)
        drink=m
        print(money)
        break

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

count = 0
total_price = 0
i = 0
while count < M:
  total_price += AB[i][0]*AB[i][1]
  count += AB[i][1]
  i += 1
  if i == N:
    break

if count == M:
  print(int(total_price))
else:
  print(int(total_price-(count-M)*AB[i-1][0]))

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
for i, j in ab:
    ans += min(m, j)*i
    m -= min(m, j)
    if m == 0:
        print(ans)
        exit()

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

SUM=0
for i in range(N):
  a,b=ab[i]
  x = min(M,b)
  SUM += a*x
  M -= x
  if M==0:break
    
print(SUM)

Solution (Python):
N,M = map(int,input().split())
D = sorted([list(map(int,input().split())) for n in range(N)])
ans = 0
num = 0

for a,b in D:
  num+=b
  ans+=a*b
  if M<=num:
    ans-=a*(num-M)
    break

print(ans)

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

num=0
money=0
i=0
while num<M:
    num+=AB[i][1]
    money+=AB[i][0]*AB[i][1]
    if i<N-1 and num<M:
    	i+=1

money+=AB[i][0]*(M-num)

print(money)

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

a.sort()
b1=0
b2=0
c=0

for i in range(n):
  b1, b2 = b1+a[i][1], b1
  if b1 <= m:
    c += a[i][0] * a[i][1]
  else:
    c += a[i][0] * (m - b2)
    break

print(c)

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

    tmp = 0
    kane = 0

    for numlis in inlis:
        a = numlis[0]
        b = numlis[1]

        if tmp + b <= m:
            tmp += b 
            kane += a * b
        
        else:
            kau = m - tmp
            tmp += kau
            kane += a * kau

        if tmp == m:
            break
    print(kane)   


if __name__ == "__main__":
    main()

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

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

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

total_cost = 0
total_drink = 0
for i in range(N):
    total_cost += sorted_AB[i][0] * sorted_AB[i][1]
    total_drink += sorted_AB[i][1]

    if total_drink >= M:
        timing_count = i
        break

answer = total_cost - (total_drink - M) * sorted_AB[timing_count][0]

print(answer)

Solution (Python):
N,M = map(int,input().split())
Shop_List = [list(map(int,input().split())) for i in range(N)]
Shop_List = sorted(Shop_List, key=lambda x:x[0])
Number_Counter = 0
Yen_Counter = 0
for i in range(N):
    if Number_Counter + Shop_List[i][1] <= M:
        Number_Counter += Shop_List[i][1]
        Yen_Counter += Shop_List[i][0]*Shop_List[i][1]
    elif Number_Counter + Shop_List[i][1] > M:
        Yen_Counter += (M-Number_Counter)*Shop_List[i][0]
        Number_Counter = M
    elif Number_Counter == M:
        break

print(Yen_Counter)

Solution (Python):
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 > 0:
        ans += a*b
        m -= b
    elif m == b:
        ans += a*b
        m -= b
        break
    else:
        ans += a*m
        break
print(ans)

Solution (Python):
N, M = map(int, input().split())
List = []
for _ in range(N):
    A, B = map(int, input().split())
    List.append((A, B))
List.sort(key=lambda x: x[0])
Res = 0
for i in range(N):
    A, B = List[i]
    if B <= M:
        M -= B
        Res += A*B
    else:
        Res += A*M
        break
print(Res)

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

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

sum_ = 0
cnt = 0
for ab in d:
    if cnt + ab[1] > M:
        sum_ += ab[0] * (M-cnt)
        break
    else:
        cnt += ab[1]
        sum_ += ab[0]*ab[1]
print(sum_)

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

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

money = 0

for i in range(n):
    if energy[i][1] < m:
        m -= energy[i][1]
        money += energy[i][1] * energy[i][0]
    else:
        money += energy[i][0] * m
        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
for ab in AB:
    t = min(m, ab[1])
    ans += ab[0]*t
    m -= t

print(ans)

Solution (Python):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB_soretd = sorted(AB, key=lambda a: a[0])
drink_cnt = 0
ans = 0
for i in range(N):
    a = AB_soretd[i][0]
    b = AB_soretd[i][1]
    if M > drink_cnt + b:
        ans += a * b
        drink_cnt += b
    else:
        for i in range(1,b+1):
            if M == drink_cnt + i:
                ans += a * i
                break
        break
print(ans)

Solution (Python):
N, M = [int(n) for n in input().split()]
A = []
for i in range(N):
    a, b = [int(n) for n in input().split()]
    A.append((a,b))
SA = sorted(A)
ans = 0
while True:
    sa = SA.pop(0)
    if sa[1] < M:
        ans += sa[0]*sa[1]
        M -= sa[1]
    else:
        ans += sa[0] * M
        break
print(ans)

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

ans = 0

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

print(ans)

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

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

cnt = 0
ans = 0
for v in xs:
    if cnt + v[1] < m:
        ans += v[0] * v[1]
        cnt += v[1]
    else:
        print(ans + v[0] * (m - cnt))
        exit()

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

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

Solution (Python):
def actual(N, M, AB):
    payment = 0

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

    for price, stock in shop_order_by_price_desc:
        if stock >= M:
            
            return payment + (price * M)
        else:
            
            M -= stock
            payment += price * stock


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

print(actual(N, M, AB))

Solution (Python):
n,m=map(int,input().split())
s=[]
for i in range(n):
    a1,b1=map(int,input().split())
    s.append([a1,b1])
s.sort()
k=0
h=0
for i in range(n):
    h+=s[i][1]
    k+=s[i][0]*s[i][1]
    if h>=m:
        k-=(h-m)*s[i][0]
        break
print(k)

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

drinks=0
ttl=0
add=0
for i in range(n):
  add=min(m-drinks, l[i][1])
  ttl=ttl+add*l[i][0]
  drinks+=add
  if drinks==m:
    print(ttl)
    exit()

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
cost = 0
for a, b in AB:
    if M >= cnt:
        cnt += b
        cost += a*b
        if cnt == M:
            print(cost)
            break
        elif cnt > M:
            cost += (M-cnt)*a
            print(cost)
            break

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.sort(key=lambda x:x[0])
count = 0 ; ans = 0
for i in range(n) :
    if list[i][1] < m - count :
        ans += list[i][0] * list[i][1]
        count += list[i][1]
    elif list[i][1] >= m - count :
        ans += list[i][0] * (m - count)
        break
print(ans)

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

ans, buy = 0, 0
for i, j in sorted(a, key=lambda x:x[0]):
    tmp = min(m-buy, j)
    ans += tmp*i
    buy += tmp
    if buy == m: break

print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, m = MI()
    a_b = [LI() for _ in range(n)]
    a_b.sort(key=lambda x:x[0])
    cnt = 0
    ans = 0
    for i in range(n):
        a = a_b[i][0]
        b = a_b[i][1]
        if cnt + b < m:
            cnt += b
            ans += a*b
        else:
            ans += a*(m - cnt)
            break
    print(ans)

if __name__ == '__main__':
    main()

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

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

cost = 0
while m > 0:
    a, b = ab.pop(0)
    if b > m:
        cost += m * a
        m = 0
    else:
        cost += b * a
        m -= b
print(cost)

Solution (Python):

(n,m,),*s=[[*map(int,i.split())]for i in open(0)]
s.sort()
ans = 0
for a,b in s:
    if m<1:
        break
    if m > b:
        ans += a*b
        m -= b
    else:
        ans += m*a
        m=0
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

n, m = map(int, input().split())
readline = sys.stdin.readline
AB = [[int(i) for i in readline().split()] for _ in range(n)]

import math

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

ans = 0

while m > 0:
    for ab in AB:
        a, b = ab[0], ab[1]
        if m > b:
            ans += a*b
            m -= b
        else:
            ans += a*m
            m = 0
            
print(ans)

Solution (Python):





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

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

    n_drink = 0
    n_store = 0
    for i in range(N):
        n_drink += AB[i][1]
        n_store = i+1
        if n_drink >= M:
            n_last = M - (n_drink - AB[i][1])
            break

    ans = 0
    for i in range(n_store-1):
        ans += AB[i][0] * AB[i][1]

    ans += AB[n_store-1][0] * n_last

    return ans


print(main())

Solution (Python):
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    s=list(map(int,input().split()))
    a.append(s[0])
    b.append(s[1])
c=zip(a,b)
d=sorted(c)


yen=0
btl=0
for i in range(n):
    if d[i][1]+btl<m:
        yen+=d[i][0]*d[i][1]
        btl+=d[i][1]
    elif d[i][1]+btl>=m:
        yen+=d[i][0]*(m-btl)
        btl=m
    if btl==m:
        print(yen)
        exit()

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

ans,i = 0,0

while(m>0):
  num = min(ab[i][1],m)
  ans += ab[i][0]*num
  
  m -= num
 
  i += 1
print(ans)

Solution (Python):
n,m=map(int,input().split())
ablist=[]
for i in range(n):
  ab=list(map(int,input().split()))
  ablist.append(ab)
ablistsort=sorted(ablist)
ans=0
ko=0
for i in range(n):
  ans+=ablistsort[i][0]*ablistsort[i][1]
  ko+=ablistsort[i][1]
  if ko>m:
      ans-=(ablistsort[i][0]*ablistsort[i][1])
      ko-=ablistsort[i][1]
      while ko<m:
        ans+=ablistsort[i][0]
        ko+=1
print(ans)

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

ab.sort()

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

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

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

def main():
    n, m = map(int, input().split())
    drinks = list()
    ans = 0
    for _ in range(n):
        drinks.append(list(map(int, input().split())))
    drinks = sorted(drinks, key=lambda x: x[0])
    for drink in drinks:
        if drink[1] >= m:
            ans += drink[0] * m
            break
        else:
            ans += drink[0] * drink[1]
            m -= drink[1]
    print(ans)
            
if __name__ == '__main__':
    main()