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())
data = []
for i in range(N):
    data.append(list(map(int, input().split())))

data.sort()

cost = 0
lost = M
for c in data:
    if lost != 0:
        if lost >= c[1]:
            lost -= c[1]
            cost += c[0] * c[1]
        else:
            cost += c[0] * lost
            lost = 0
    else:
        break
print(cost)

Solution (Python):
N,M= [ int(it) for it in input().split() ]
li = []
for i in range(N):
  li.append( [ int(it) for it in input().split() ] )
li.sort( key = lambda x:x[0] )
c = 0
for i in range(N):
  m = min( li[i][1], M )
  c += m*li[i][0]
  M -= m
print ( c )

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])
ans = 0
count = 0
i = 0

while True:
  ans += AB[i][0] * AB[i][1]
  count += AB[i][1]
  if count >= M:
    break
  i += 1
ans -= AB[i][0] * (count - M)
print(ans)

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

for i in range(N):
    AB[i] = [int(n) for n in input().split()]
AB = sorted(AB, key=lambda x: x[0])

ans = 0
for i in range(len(AB)):
    while(M != 0 and AB[i][1] != 0):
        M -= 1
        AB[i][1] -= 1
        ans += AB[i][0]
print(ans)

Solution (Python):
def key_func(n):
    return n[0]

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

a_b.sort(key=key_func)

money = 0

for item in a_b:
    i = min(m,item[1])
    money = money + item[0]*i
    m = m - i
    if m <= 0:
        break

print(money)

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

shop_list = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    shop_list[i][0] = A[i]
    shop_list[i][1] = B[i]

shop_list.sort()

count = 0
money = 0
for i in range(N):
    if count + shop_list[i][1] < M:
        money += shop_list[i][0] * shop_list[i][1]
        count += shop_list[i][1]
    else:
        for j in range(shop_list[i][1]):
            if count == M:
                break
            money += shop_list[i][0]
            count += 1

print(money)

Solution (Python):
from collections import deque
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort()

ab = deque(ab)

ans = 0
m = 0
while m < M:
    a, b = ab.popleft()
    tm = min([b, M - m])
    ans += tm * a
    m += tm
print(ans)

Solution (Python):

from operator import itemgetter


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

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


def main():
    b = sorted(a, key=itemgetter(0))
    m = 0
    cost = 0
    for i in range(N):
        if (m + b[i][1]) <= M:
            m += b[i][1]
            cost += (b[i][0] * b[i][1])
        else:
            cost += (b[i][0] * (M-m))
            return cost
    return cost


print(main())

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

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

money = 0
count = 0

drink.sort()
for i in range(n):
    if m <= drink[i][1]:
        break
    m -= drink[i][1]
    money += drink[i][0] * drink[i][1]
    count += 1

money += drink[count][0] * m
print(money)

Solution (Python):
import sys
rr = lambda: sys.stdin.readline().strip()
ri = lambda: int(rr())
rs = lambda: [int(_) for _ in rr().split()]

from operator import itemgetter

N, M = rs()
p = [tuple(rs()) for _ in range(N)]

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

ans = 0
m = 0

for pi in p:
	m += pi[1]
	ans += pi[0] * pi[1]
	if m >= M:
		ans -= (m - M) * pi[0]
		break

print(ans)

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

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

drinks.sort()

ans = 0
req = M
for a, c in drinks:
    cnt = min(c, req)
    ans += a * cnt
    req -= cnt

print(ans)

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

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

p = 0
q = 0
for a, b in sorted(price):
    for i in range(b):
        p += a
        q += 1
        if q == M:
            break
    if q == M:
        break

print(p)

Solution (Python):
def main():
  N, M = map(int, input().split())
  arr = []
  for i in range(N):
    cost, num = map(int, input().split())
    arr.append((cost, num))
  arr.sort(key=lambda x: x[0])

  cost = 0
  num = 0
  for i in range(N):
    n = arr[i][1]
    cost += arr[i][0] * min(n, M - num)
    num += n
    if num >= M:
      print(cost)
      return


if __name__ == "__main__":
  main()

Solution (Python):
from operator import itemgetter
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=sorted(a,key=itemgetter(0))
buy=0
money=0
for j in range(n):
  if buy+b[j][1]<m:
    money+=b[j][0]*b[j][1]
    buy+=b[j][1]
  else:
    money+=(m-buy)*b[j][0]
    print(money)
    break

Solution (Python):
N, M = map(int, input().split())
A = [None] * N
B = [None] * N
C = [None] * N
for i in range(N):
  A[i], B[i] = map(int, input().split())
  C[i] = [A[i], B[i]]
C = sorted(C)

count = 0
price = 0
for i in range(N):
  price += C[i][0] * C[i][1]
  count += C[i][1]
  if (count >= M):
    break

price -= (count - M) * C[i][0]


print(price)

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

X = sorted(X)
num = 0
cost = 0
for a, b in X:
    cost += a * min(M - num, b)
    num += min(M - num, b)
    if num == M:
        print(cost)
        break

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

value_nums = [] 
for _ in range(N):
  v,n = map(int, input().split())
  value_nums.append([v,n])
  
  
vn_sorted = sorted(value_nums, key = lambda x: x[0])


ans = 0
for value, num in vn_sorted:
  if M >= num:
    ans += value * num
    M -= num
  elif 0 <= M < num:
    ans += value * M
    M = 0
    break
  
print(ans)

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

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

l = sorted(l, key = lambda x: x[0])
p = 0
for v in l:
    if m >= v[1]:
        m = m - v[1]
        p += v[0] * v[1]
    elif m < v[1]:
        p += v[0] * m
        m = 0
        
    if m == 0:
        break
        
print(p)

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])
ans = 0
for i in a:
    if i[1] > m:
        ans += i[0] * m
        break
    else:
        ans += i[0] * i[1]
        m -= i[1]
print(ans)

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

drinks = sorted(drinks, key=lambda d: d[0])
i = 0
while M > 0:
    M -= drinks[i][1]
    i += 1
ans = sum([d[0] * d[1] for d in drinks[:i]])
if M < 0:
    ans -= abs(M) * drinks[i - 1][0]
print(ans)

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

Solution (Python):
n, m, *l= map(int, open(0).read().split())

ans = 0
for price, amount in sorted(zip(l[::2], l[1::2])):
    ans += price * min(m, amount)
    m -= amount
    if m <= 0:
        break
print(ans)

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

ans = 0
for price, amount in sorted(zip(A, B)):
    ans += price * min(m, amount)
    m -= amount
    if m <= 0:
        break
print(ans)

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

ans = 0
for price, amount in sorted(zip(A, B)):
    ans += price * min(m, amount)
    m -= amount
    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()
i = 0
ans = 0
while M > 0:
    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):
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    N = input_list[0]
    M = input_list[1]

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

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

    answer = 0
    cnt = 0
    for e in sorted_AB:
        pre_cnt = cnt

        Ai = e[0]
        Bi = e[1]

        cnt = min(M, cnt+Bi)
        answer += Ai * (cnt - pre_cnt)

        if cnt == M:
            break

    print(answer)

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

count = 0
money = 0
for ab in ordered:
    a = ab[0]
    b = ab[1]
    if M >= count + b:
        count += b
        money += b * a
    else:
        c = (M - count)
        count += c
        money += c * a
        break

print(money)

Solution (Python):
from operator import itemgetter
N,M = map(int, input().split())

all_lst = []
for i in range(N):
  all_lst.append(list(map(int, input().split())))
  
all_lst.sort(key=itemgetter(0))

m = 0
ans = 0

for i in all_lst:
  a = i[0]
  b = i[1]
  if (b <= (M - m)):
    ans += a * b
    m += b
  else:
    ans += a * (M - m)
    m += (M - m)
    break
print(ans)

Solution (Python):
from operator import itemgetter
N,M = map(int, input().split())

all_lst = []
for i in range(N):
  all_lst.append(list(map(int, input().split())))
  
all_lst.sort(key=itemgetter(0))

m = 0
ans = 0

for i in all_lst:
  a = i[0]
  b = i[1]
  if (m < M):
    if (b <= (M - m)):
      ans += a * b
      m += b
    else:
      ans += a * (M - m)
      m += (M - m)
  else:
    break
print(ans)

Solution (Python):
n,m = map(int, input().split())
lst = [[]]*n
num = 0
price = 0

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

i = 0
while num < m:
    num += lst[i][1]
    price += lst[i][0]*lst[i][1]
    i += 1

print(price - (num-m)*lst[i-1][0])

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

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

amt = 0
money = 0
i=0
while amt<M:
    money+=List[i][0]*List[i][1]
    amt+=List[i][1]
    i+=1

ans = money-(amt-M)*List[i-1][0]
print(ans)

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

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

def dfs(m,cnt):
    if m <= 0 or cnt == len(list):
        return 0
    b = list[cnt][1] if list[cnt][1] < m else m
    a = b*list[cnt][0]

    return a + dfs(m-b,cnt+1)

print(dfs(M,0))

Solution (Python):
from operator import itemgetter

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





A.sort(key=itemgetter(0))

sum = 0
for shop in A:
    num = min(shop[1], M)
    sum += shop[0] * num
    M -= num
    

    if M <= 0:
        break
print(sum)

Solution (Python):


from bisect import bisect_left as binl

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return map(int, input_tuple)


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


def intinl(count):
    return [intin() for _ in range(count)]


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x





def main():
    n, m = intin()
    ablist = intinl(n)
    ablist = [(a, b) for a, b in ablist]

    ablist.sort()

    count = 0
    yen = 0
    for a, b in ablist:
        if count + b >= m:
            yen += a * (m - count)
            count = m
            break
        yen += a * b
        count += b

    print(yen)


if __name__ == '__main__':
    main()

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 a, b in ab:
    if now == M:
        break
    buy = min(b, M-now)
    now += buy
    ans += buy * a
print(ans)

Solution (Python):
N,M=map(int,input().split())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB)
c=-1
while M>0:
    M-=AB[c+1][1]
    c+=1
S=[(AB[c][1]+M)*AB[c][0]]
for k in range(c):
    S.append(AB[k][0]*AB[k][1])
print(sum(S))

Solution (Python):
N,M=map(int,input().split())
AB=[]
for i in range(N):
    ab=list(map(int,input().split()))
    AB.append(ab)
AB=sorted(AB)
K=M
c=-1
while K>0:
    K-=AB[c+1][1]
    c+=1
S=[(AB[c][1]+K)*AB[c][0]]
for k in range(c):
    S.append(AB[k][0]*AB[k][1])
print(sum(S))

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

Solution (Python):
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[[c,d]]
e.sort()
a=i=j=0
while i < b:
    a+=(e[j][0]*e[j][1])
    i+=e[j][1]
    j+=1
print(a-((i-b)*e[j-1][0]))

Solution (Python):
from operator import itemgetter
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=itemgetter(0))
s=0
for j in range(n):
  s=s+l[j][0]*min(l[j][1],m)
  m=m-l[j][1]
  if m<0:
    break
print(s)

Solution (Python):
M,N=(int(i) for i in input().split())
AB=[]
for i in range(M):
  AB.append([int(i) for i in input().split()])
sortedAB=sorted(AB,key=lambda x:x[0])
t=0
i=0
money=0
while t<N:
  if N-t<sortedAB[i][1]:
    money=money+(N-t)*sortedAB[i][0]
    t=N
  else:
    t=t+sortedAB[i][1]
    money=money+sortedAB[i][0]*sortedAB[i][1]
  i+=1
print(money)

Solution (Python):
a, b = map(int, input().split())
A = []
for i in range(a):
    array = list(map(int, input().split()))
    A.append(array)
A.sort()
ans = 0
buy = 0
for i in A:
    buy = min(b, i[1])
    ans += i[0]*buy
    b -= buy
    if b == 0:
        break
print(ans)

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

A_array = array[:, 0]
B_array = array[:, 1]

buy_total = 0
money_count = 0
buy_order = np.argsort(A_array)

for buy_index in buy_order:
    buy_count = min(M - buy_total, B_array[buy_index])
    buy_total += buy_count
    money_count += buy_count * A_array[buy_index]
    if buy_total == M:
        break
print(money_count)

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

Solution (Python):

N, M = map(int, input().split())
list_drink = []
for n in range(N):
    list_drink.append(list(map(int, input().split())))
    
list_drink.sort()

sum_bottle = 0
sum_money = 0
cnt_lp = 0
while(sum_bottle <= M - 1):
    num_money = list_drink[cnt_lp][0]
    num_bottle = list_drink[cnt_lp][1]
    if sum_bottle + num_bottle >= M:
        sum_money += num_money * (M - sum_bottle)
        sum_bottle = M
    else:
        sum_money += num_money * num_bottle
        sum_bottle += num_bottle
    cnt_lp += 1

print(sum_money)

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

A = sorted(store)

sumQ = 0
sumP = 0
for k in range(N):
    p = A[k][0]
    q = A[k][1]
    sumQ = sumQ + q
    sumP = sumP + p * q
    if M < sumQ:
        print(sumP-(sumQ-M)*p)
        break
    elif M == sumQ:
        print(sumP)
        break

Solution (Python):
import numpy as np

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

B = sorted(A)

cnt = 0
amount = 0
for i in range(N):
  if cnt+B[i][1] < M:
    cnt += B[i][1]
    amount += B[i][0]*B[i][1]
  elif cnt+B[i][1] >= M:
    
    amount += B[i][0]*(M-cnt)
    break

print(amount)

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

array.sort(key=lambda x: x[0])
ans = 0
cnt = 0
for i in range(N):
  
  buy = min([array[i][1], M-cnt])
  cnt += buy
  ans += array[i][0]*buy

print(ans)

Solution (Python):
import sys

N, M = map(int, input().split())
lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]
lst.sort()    

count = M
yen = 0

for i in range(N):
    yen += lst[i][0] * min(count, lst[i][1])  
    count -= min(count, lst[i][1])

    if count <= 0:
        print (yen)
        sys.exit()

Solution (Python):
n, m = [int(i) for i in input().split()]
a = [[0, 0] for _ in range(n)]
for i in range(n):
    a[i] = [int(i) for i in input().split()]
a.sort()
_sum = 0
for i in range(len(a)):
    _sum += a[i][0] * min(m, a[i][1])
    m -= min(m, a[i][1])
print(_sum)

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    AB = ii2nnn(N)
    AB.sort(key=lambda v: v[0])
    cost = 0
    m = 0
    i = 0
    while True:
        a, b = AB[i]
        if m + b < M:
            m += b
            i += 1
            cost += a * b
            continue
        for j in range(b):
            m += 1
            cost += a
            if m >= M:
                print(cost)
                return

main()

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

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

ab.sort(key=lambda ab:(ab[0]))
s = 0
cnt = 0
for i in range(M):
    s += ab[cnt][0]
    if ab[cnt][1]>1:
        ab[cnt][1] -= 1
    else:
        cnt += 1
print(s)

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

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

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

remain = M
cost = 0

for a, b in AB:
    if remain <= b:
        cost += remain * a
        break
    else:
        cost += a * b
        remain -= b


print(cost)

Solution (Python):


class Shop():
    def __init__(self, v, n):
        self.value = v
        self.zaiko = n

def solve():
    N, M = list(map(int, input().split()))
    shops = []
    for i in range(N):
        a, b = list(map(int, input().split()))
        shops.append(Shop(a, b))
    
    shops.sort(key=lambda x: x.value)

    rest = M
    ans = 0
    for i in range(N):
        if shops[i].zaiko <= rest:
            ans += shops[i].value * shops[i].zaiko
            rest -= shops[i].zaiko
        else:
            ans += shops[i].value * rest
            break
    
    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
N, M = map(int, input().split())
AB = sorted(list(map(int, input().split()))for i in range(N))
ans = 0
for A, B in AB:
    if B >= M:
        print(ans + A * M)
        exit()
    else:
        ans += A * B
        M -= B

Solution (Python):
from operator import itemgetter

N, M = map(int, input().split())
AB = sorted([list(map(int, input().split()))for i in range(N)], key=itemgetter(0))
ans = 0
cm = 0
for i in range(N):
    if cm + AB[i][1] >= M:
        print(ans + AB[i][0] * (M - cm))
        exit()
    else:
        ans += AB[i][0] * AB[i][1]
        cm += AB[i][1]

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

a = 0
while True:
    s = AB.pop(0)
    if M > s[1]:
        M -= s[1]
        a += s[0] * s[1]
    else:
        a += s[0] * M
        break

print(a)

Solution (Python):
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)])
res = 0
for a, b in AB:
    res += a * min(b, M)
    M -= b
    if 0 >= M:
        break
print(res)

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

ds.sort(key=lambda x: x[0])
ans = 0
for a, b in ds:
    if m < b:
        ans += a * m
        break
    else:
        ans += a * b
        m -= b
print(ans)

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

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

print(ans)

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

data =[]
for i in range(n):
    tmp_a, tmp_b = list(map(int, input().split()))
    data.append((tmp_a, tmp_b))


total =0
cost = 0
for a, b in sorted(data, key=lambda x:x[0]):
    
    if total + b < m:
        total += b
        cost += a*b
    else:
        cost += a*(m-total)
        break
print(cost)

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

count = 0
cost = 0
index = 0

while True:
  if index > n - 1:
    break
  if count + sorteddrink[index][1] > m:
    break
  cost += sorteddrink[index][0] * sorteddrink[index][1]
  count += sorteddrink[index][1]
  index += 1

if index <= n - 1:
  cost += sorteddrink[index][0] * (m - count)
print(cost)

Solution (Python):

import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    rem = M
    ret = 0
    for a, b in sorted(zip(A, B)):
        ret += a * min(b, rem)
        rem -= min(b, rem)
        if rem == 0:
            break
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    result = solve(N, M, A, B)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter
N, M = map(int,input().split())
lists = []
num = 0
amount = 0

for i in range(N):
    lists.append(list(map(int, input().split())))

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

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

print(amount)

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

m = sorted([tuple(map(int, input().split())) for _ in range(N)])
need = M 
totalprice = 0 

for i, nowmer in enumerate(m):
    nowprice = nowmer[0]
    stock = nowmer[1]
    totalprice += nowprice * min(need, stock)
    need -= min(need, stock)
    if need <= 0: break

print(totalprice)

Solution (Python):
import sys
from operator import itemgetter

input = sys.stdin.readline

N, M = map(int, input().split())
C = [None] * N
for i in range(N):
    a, b = map(int, input().split())
    C[i] = [a, b]
C = sorted(C, key=itemgetter(0))

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

Solution (Python):
N,M=map(int,input().split())
D=[]
for n in range(N):
    a,b=map(int,input().split())
    D.append((a,b))
D.sort()
c=0
m=0
for n in range(N):
    a,b=D[n]
    if m+b<M:
        m+=b
        c+=b*a
    else:
        bb=M-m
        m+=bb
        c+=bb*a
print(c)

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


drink_num = 0
drink_cost = 0
for key, value in sorted(dic.items()):
    if drink_num + value >= M:
        drink_cost += (M - drink_num)*key
        break
    else:
        drink_cost += key*value
        drink_num += value

print(drink_cost)

Solution (Python):


N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)

Solution (Python):


import numpy as np


N, M = map(int, raw_input().split())
list = [map(int, raw_input().split()) for i in range(0, N)]

arr = np.array(list)

arrsort = arr[arr[:,0].argsort()]

hon = 0
yen2 = 0
yen3 = 0

for x in range(0,N):
            yen3 += yen2
            for i in range(0,arrsort[x,1]):
                yen2 = arrsort[x,0] * (i+1)
                hon += 1
                if hon == M:
                    break
                else:
                    continue
                break
            else:
                continue
            break

print(yen3 + yen2)

Solution (Python):


import numpy as np


N, M = map(int, raw_input().split())
list = [map(int, raw_input().split()) for i in range(0, N)]






arr = np.array(list)




arrsort = arr[arr[:,0].argsort()]



yen = arrsort[0,0] * arrsort[0,1]




    



hon = 0
yen2 = 0
yen3 = 0

for x in range(0,N):
            yen3 += yen2
            
            
            
            for i in range(0,arrsort[x,1]):
                yen2 = arrsort[x,0] * (i+1)
                
                hon += 1
                if hon == M:
                    break
                else:
                    continue
                break
            else:
                continue
            break




print(yen3 + yen2)

Solution (Python):
n,m= map(int, input().split())
x = {}
for i in range(n):
    a,b = map(int, input().split())
    if a not in x:
        x[a] = b
    else:
        x[a] += b

s = sorted(x.keys())

ans = 0
c = 0
for ss in s:
    
    if c + x[ss] <= m:
        ans += ss * x[ss]
        c += x[ss]
    else:
        ans += ss * (m-c)
        break
print(ans)

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

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stores.append((Ai, Bi))    

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

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

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

d_list = sorted(d_list)

for j in range(len(d_list)):
  p1 = d_list[j][0]
  p2 = d_list[j][1]
  if m > p2:
    m -= p2
    total += p1 * p2
  else:
    total += p1 * m
    break

print(total)

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

Solution (Python):


def main():
    N,M = map(int,input().split())
    stores = []
    cost = 0
    number = 0

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

    for store in stores:
        if number + store[1] >= M:
            cost += (M - number)*store[0]
            break
        else:
            number += store[1]
            cost += store[0]*store[1]

    print(cost)

if __name__ == "__main__":
    main()

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

A_B_AB_list = []
for i in range(N):
    A,B = map(int,input().split())
    A_B_AB = [A,B,A*B]
    A_B_AB_list.append(A_B_AB)
A_B_AB_list.sort()
B_sums = [0]*(N+1)
AB_sums = [0]*(N+1)
for i in range(N):
    B_sums[i+1] = B_sums[i] + A_B_AB_list[i][1]
    AB_sums[i+1] = AB_sums[i] + A_B_AB_list[i][2]
for i in range(1,N+1):
    if B_sums[i] >= M:
        amari = M - B_sums[i-1] 
        ans = AB_sums[i-1] + amari*A_B_AB_list[i-1][0]
        print(ans)
        break

Solution (Python):
n,m = map(int,input().split())
price = []
honsu = []
c = []
for i in range(n):
  a,b = map(int,input().split())
  c.append([a,b])
c = sorted(c)
price,honsu=zip(*c)
money = 0
l = 0
while m > 0:
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  l += 1
print(money)