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

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

AB = []
for i in range(N):
  A, B = map(int,input().split())
  AB.append([A,B])
AB = sorted(AB,key = lambda x:x[0])
cost = 0

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)

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

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

AB.sort()

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

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

sum = 0
mr = 0
ks = sorted(k)

for i in range(n):
    if ks[i][1] < (m-mr):
        sum += ks[i][0] * ks[i][1]
        mr += ks[i][1]

    else:
        sum += ks[i][0] * (m - mr)
        break

print(sum)

Solution (Python):
def solve():
    N, M = [int(i) for i in input().split()]
    D = [[int(i) for i in input().split()] for _ in range(N)]
    D.sort(key=lambda x: x[0])
    ans = 0
    for d in D:
        a, b = d
        ans += a * min(M, b)
        M -= min(M, b)
        if M == 0:
            print(ans)
            exit()

if __name__ == "__main__":
    solve()

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

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

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

ll.sort()

t = 0
cst = 0
i = 0
while t < m:
    t += ll[i][1]
    cst += ll[i][0]*ll[i][1]
    if t > m:
        cst -= ll[i][0]*(t-m)
    i += 1
print(cst)

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

Solution (Python):

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

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

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

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

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

    cost = 0
    temp_i = 0
    ab.sort(key=lambda x: x[0])
    for i in range(n):
        cost += ab[i][0] * ab[i][1]
        m -= ab[i][1]
        if m <= 0:
            temp_i = i
            break

    if m == 0:
        print(cost)
    elif m < 0:
        cost += ab[temp_i][0] * m
        print(cost)


if __name__ == '__main__':
    main()

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

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

n, m = map(int, input().split())
prices = [0] * n
for i in range(n):
    prices[i] = tuple(map(int, input().split()))
prices = sorted(prices)

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

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

def main():
    n, m = map(int, input().split())
    ab = [(0, 0)] * n
    for i in range(n):
        ab[i] = tuple(map(int, input().split()))

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

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

main()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, m = LI()
    lst = []
    for _ in range(n):
        a, b = LI()
        lst.append([a,b])

    lst.sort()

    ans = 0
    for i in range(n):
        tem = lst[i][1]
        lst[i][1] = max(0, lst[i][1]-m)
        bought = tem-lst[i][1]
        m -= bought
        ans += lst[i][0]*bought
        if m == 0:
            break

    print(ans)   
main()

Solution (Python):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a = sorted(a, key=lambda x:x[0])
money = 0
drink = 0
for i in range(n):
  for j in range(a[i][1]):
    drink += 1
    money += a[i][0]
    if drink == m:
      print(money)
      exit()

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

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

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

sum = 0
price = 0
for d in drinks:
    if sum + d[1] < M:
        sum += d[1]
        price += d[0]*d[1]
    else:
        price += d[0]*(M-sum)
        break

print(price)

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

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

Solution (Python):

"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

N, M = map(int, input().split())
drinks = list()
for i in range(N):
  a, b = map(int,input().split())
  drinks.append((a,b))

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

ans = 0
i = 0
while M > 0:
    a, b = drinks[i]
    i += 1
    if M <= b:
        ans += a*M
        M = 0
    else:
        ans += a*b
        M -= b
    
print(ans)

Solution (Python):

"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

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

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

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

ans = 0
while M > 0:
    a, b = drinks.pop(0)
    if M <= b:
        ans += a*M
        M = 0
    else:
        ans += a*b
        M -= b
    
print(ans)

Solution (Python):
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    a_b_dict = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        a_b_dict[a] += b
    ans = 0
    for a, b in sorted(a_b_dict.items()):
        if M >= b:
            M -= b
            ans += a * b
        else:
            ans += a * M
            break
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):





def resolve():
    import sys
    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    ab = {}
    for _ in range(n):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        if a not in ab:
            ab[a] = 0
        ab[a] += b

    a_list = sorted(ab.keys())
    ans = 0
    for a in a_list:
        if m <= ab[a]:
            ans += m * a
            break
        else:
            ans += ab[a] * a
            m -= ab[a]

    print(ans)



if __name__ == "__main__":
    resolve()

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

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

ab.sort()

payment = 0

for i in ab:
  price = i[0]
  amount = i[1]
  if amount > m:
    amount = m
  m -= amount
  payment += amount*price
  if m == 0:
    break

print(payment)

Solution (Python):



import sys

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

ls = []

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

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

ans = 0

for l in ls:
    if l[1] <= M:
        M -= l[1]
        ans += l[0] * l[1]
    else:
        ans += l[0] * M
        break


print(ans)

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

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

li.sort()

g=0
s=0

for i in range(N):
    if li[i][1]+s<M:
        s+=li[i][1]
        g+=li[i][1]*li[i][0]
    else:
        g+=(M-s)*li[i][0]
        print(g)
        exit()

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()
c=0
for a,b in l:
  c+=min(b,m)*a
  m=max(m-b,0)

print(c)

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

Solution (Python):
n, m = map(int, input().split())
stores = [list(map(int, input().split())) for _ in range(n)]
sorted_sotres = sorted(stores, key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_sotres:
    if number > m:
        ans += cost * m
        break
    elif number == m:
        ans += cost * number
        break
    else:
        ans += cost * number
    m -= number
print(ans)

Solution (Python):

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


def input_array():
	return list(map(int,input().split()))
  

n,m=input2()
AB=[input_array() for _ in range(n)]

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

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

Solution (Python):
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    data = sorted([Input() for _ in range(n)])
    amount = 0
    for x, y in data:
        get1 = min(y, m)
        m = m - get1
        amount += get1 * x
        if m <= 0:
            return amount

print(main())

Solution (Python):
n,m = map(int, input().split(" "))
a = sorted(list(map(int, input().split(" "))) for i in range(n))
total = 0
for i, j in a:
  if j < m:
    m -= j
    total += i * j
  else:
    total += i * m
    break
print(total)

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

Solution (Python):
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
 
ab_sorted = sorted(ab, key=lambda x:x[0])
 
num = 0
amount_of_money = 0

for i in range(n):
    buy = min(ab_sorted[i][1], m-num)
    num += buy
    amount_of_money += ab_sorted[i][0] * buy
        
    if num >= m:
        print(amount_of_money)
        exit(0)

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

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

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)
    exit(0)

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

ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    
    i += 1
print(cost)

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

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

print(ans)

Solution (Python):
from itertools import accumulate

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

sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))

num = 0
ans = 0
index_ = -1
for a, b in sAB:
    index_ += 1
    num += b
    if num >= M:
        break
    ans += a*b

if index_ == 0:
    ans += sAB[0][0]*M
else:
    ans += sAB[index_][0]*(M-cum_num[index_-1])

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()
ans = 0
for a,b in list:
  ans += min(b,M)*a
  M = max(0,M-b)
print(ans)

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

Solution (Python):
N,M = map(int,input().split())
lsd = []
for i in range(N):
    lsd.append(list(map(int,input().split())))
lsd.sort(key=lambda x:x[0])
ans = 0
i = 0
while M != 0:
    if M >= lsd[i][1]:
        ans += lsd[i][0]*lsd[i][1]
        M -= lsd[i][1]
    else:
        ans += lsd[i][0]*M
        M = 0
    i += 1
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





N, M = getNM()
que = [getList() for i in range(N)]
que.sort(reverse = True)

left = M
ans = 0
while left > 0:
    a, b = que.pop()
    buy = min(left, b)
    left -= buy
    ans += buy * a
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 = m -ab[i][1]
    elif 0 < m < ab[i][1] :
        ans += m*ab[i][0]
        break
print(ans)

Solution (Python):
n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
sell=sorted(sell.items())
if m<=sell[0][1]:
  print(m*(sell[0][0]))
  exit()
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    exit()
  else:
    buy+=(lis[0])*(lis[1])

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

Solution (Python):
def main():
    n, m = map(int, input().split())
    ab_list = [list(map(int, input().split())) for _ in range(n)]
    ab_list.sort(key=lambda x: x[0])
    ans = 0

    for ab in ab_list:
        a, b = ab[0], ab[1]
        if b <= m:
            ans += a * b
            m -= b
        else:
            ans += a * m
            break

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n, m = map(int, input().split())
    ab_list = [list(map(int, input().split())) for _ in range(n)]
    ab_list.sort(key=lambda x: x[0])
    ans, cnt = 0, 0

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N,M=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
List.sort()
res = 0
num = 0
i = 0
while num < M:
  if List[i][1] != 0:
    pass
  else:
    i +=1
  num += 1
  res += List[i][0]
  List[i][1] += -1
print(res)

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

AB.sort()
cost = 0
cnt = 0
i = 0
while(cnt<M):
  a, b = AB[i]
  if M-cnt<=b:
    cost += a * (M-cnt)
    cnt = M
    break
  cost += a * b
  cnt += b
  i += 1
ans = cost
print(ans)

Solution (Python):
N, M = map(int, input().split())
store_m = [list(map(int, input().split())) for i in range(N)]
store = sorted(store_m)
buy = 0
cost = 0
for i in range(N):
    buy += store[i][1]
    if buy < M:
        cost += store[i][0] * store[i][1]
    else:
        cost += store[i][0] * (M - (buy - store[i][1]))
        print(cost)
        exit()

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

s = [tuple(map(int, input().split())) for _ in range(n)]
s.sort()

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

print(ans)

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

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

Solution (Python):
N, M = map(int, input().split())
pAc = [list(map(int, input().split())) for _ in range(N)]
pAc.sort()
count = 0
price = 0
for p,c in pAc:
    if count + c >= M:
        print(price+(M-count)*p)
        exit()
    count += c
    price += p*c

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

import sys
if n ==1:
    print(ca[0][0]*ca[0][1])
    sys.exit()
money = 0
i = 0
num = 0
while True:
    
    if num + ca[i][1] < m:
        num += ca[i][1]
        money += ca[i][0] * ca[i][1]
        i += 1
        
    else:
        money += ca[i][0]*(m-num)
        break    
print(money)

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

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

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

lis.sort()

for x in lis:
  a, b = x
  if m >= b:
    m -= b
    ans = ans + (a*b)
  else:
    ans = ans + (a*m)
    break
  
print(ans)

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

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

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

print(ans)

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

AB.sort()

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

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

for m in range(M):
  if D+X[m][1]<M:
    D+=X[m][1]
    G+=X[m][0]*X[m][1]
  else:
    G+=X[m][0]*(M-D)
    print(G)
    exit()

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

Solution (Python):
N,M=map(int,input().split())
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort(key = lambda x:x[0])
x,y = [list(i) for i in zip(*xy)]
nokori=M
ans=0
for i in range(N):
  ans+=x[i]*min(y[i],nokori)
  nokori-=y[i]
  if nokori<=0:
    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 a, b in ab:
    ans += a * min(b, m)
    m -= b
    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 = sorted(ab)

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

print(money)

Solution (Python):

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

X.sort()
res = M
ans = 0
for a, b in X:
    if res <= 0:
        break

    tmp = min(b, res)
    res -= tmp
    ans += tmp * a

print(ans)

Solution (Python):
n,m = map(int,input().split())
dic = {}
for i in range(n):
    a,b = map(int,input().split())
    dic.setdefault(a,0)
    dic[a] += b

nedan = sorted(dic)

ans = 0
for yen in nedan:
    if dic[yen] < m:
        
        ans += yen * dic[yen]
        m -= dic[yen]
    else:
        
        ans += yen * m
        break
print(ans)

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

Solution (Python):

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

A_B = sorted(A_B, key = lambda x:x[1],reverse = True)
A_B = sorted(A_B, key = lambda x:x[0], reverse = False)

pay = 0
drink = M
for A, B in A_B:
    if drink <= B:
        pay += A*drink
        break
    else:
        pay += A*B
        drink -= B
print(pay)

Solution (Python):
def resolve():
    N, M = map(int, input().split())
    A = []
    for _ in range(N):
        a = list(map(int, input().split()))
        A.append(a)
    ans = 0
    for i, j in sorted(A, key=lambda x: x[0]):
        if j >= M:
            ans += M * i
            print(ans)
            exit()
        ans += i * j
        M -= j
resolve()

Solution (Python):
from operator import itemgetter

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

i = 0
ans = 0
while m >0:
  if ab[i][1]<=m:
    m -= ab[i][1]
    ans += ab[i][0]*ab[i][1]
  else:
    ans += ab[i][0]*m
    m = 0
  i+=1
print(ans)

Solution (Python):
from collections import defaultdict
N, M = map(int,input().rstrip().split())
d = defaultdict(lambda: 0)
for _ in range(N):
    A, B = map(int,input().rstrip().split())
    d[A] += B
ans=0
for k in sorted(d.keys()):
    if d[k]<=M:
        ans += k*d[k]
    else:
        ans += k*M
    M -= d[k]
    if M<=0:break
print(ans)

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

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

Solution (Python):
n,m=map(int,input().split())
dic={}
doll=0
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
for k,v in AB:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    print(doll)
    exit()

Solution (Python):
n,m=map(int,input().split())
dic={}
doll=0
AB=[list(map(int,input().split())) for _ in range(n)]

AB.sort()

for k,v in AB:
  if v<m:
    doll+=k*v
    m-=v
  else:
    doll+=k*m
    break
print(doll)

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

    a.append([int(k),int(j)])
a=sorted(a)
for i in range(n):
    if a[i][1]>=m:
        cnt+=a[i][0]*m
        break
    else:
        cnt+=a[i][0]*a[i][1]
        m-=a[i][1]
print(cnt)

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

for i in range(N):
    buy = min(M,A[i][1])
    ans += buy * A[i][0]
    M -= buy
print(ans)

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

ans = bought = 0
for a, b in AB:
    m = min(M - bought, b)
    bought += m
    ans += a * m
print(ans)

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

ans = 0
bought = 0
for a, b in AB:
    m = min(M - bought, b)
    bought += m
    ans += a * m
print(ans)

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

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

result = 0
for x in a:
  cnt = min(m, x[1])
  result += x[0] * cnt
  m -= cnt
print(result)

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

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

    l.sort()
    ans = 0
    for i in l:
        if m<=i[1]:
            ans += m*i[0]
            break
        else:
            ans += i[0]*i[1]
            m -= i[1]
    print(ans)

if __name__=="__main__":
    main()

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

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

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

Solution (Python):
n,m=map(int,input().split())
dp=[[0]*2 for i in range(n)]
ans,x=0,0
for i in range(n):
  a,b=map(int,input().split())
  dp[i][0]=a
  dp[i][1]=b
dp.sort()
while m>0:
  dp[x][1]-=1
  ans+=dp[x][0]
  m-=1
  if dp[x][1]==0:
    x+=1
print(ans)

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

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())
    X = [(a, b) for a, b in zip(*[iter(AB)] * 2)]

    X.sort()

    ans = 0
    n = 0
    for a, b in X:
        if n + b >= M:
            ans += (M - n) * a
            break
        else:
            ans += a * b
            n += b

    print(ans)
    return


if __name__ == '__main__':
    main()

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

m = 0
money = 0
for i in range(N):
    if m + price[i][1] < M:
        money += price[i][0] * price[i][1]
        m += price[i][1]
    else:
        money += price[i][0] * (M-m)
        break
print(money)

Solution (Python):


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

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

ab_list.sort()
ans = 0
num = 0
for ab in ab_list:
    ans += ab[0]*ab[1]
    num += ab[1]
    if num >= m:
        i_stop=ab_list.index(ab)
        break
diff_num = num - m
ans -= diff_num * ab_list[i_stop][0]
print(ans)

Solution (Python):
n,m = map(int,input().split())
x = [list(map(int,input().split())) for l in range(n)]
x = sorted(x)
count = m
p = 0
for i in x:
  if count >= i[1]:
    count -= i[1]
    p += i[0] * i[1]
  elif count ==0:
    break
  else:
    p += i[0] * count
    count = 0

print(p)