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

import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB = [(a,b) for (a,b) in zip(A,B)]
    AB = sorted(AB, key=lambda ab: ab[0])
    val = 0
    for (a,b) in AB:
        if M == 0:
            break
        if M >= b:
            val += a * b
            M -= b
        else:
            val += a * M
            M = 0
    print(val)
    return


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))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Solution (Python):
lst=input().split(" ")
N=int(lst[0])
M=int(lst[1])
cost=0
drinks=[]
for i in range(N):
    lst=input().split(" ")
    drinks.append([int(lst[0]),int(lst[1])])
drinks.sort(key=lambda x:x[0])
for d in drinks:
    if M>d[1]:
        M -= d[1]
        cost += d[0]*d[1]
    else:
        cost += d[0]*M
        break

    
print(cost)

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

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

ab = sorted(ab)

now_M = 0
money = 0
for ab_i in ab:
    if M <= now_M:
        break
    elif M <= now_M + ab_i[1]:
        money += ab_i[0] * (M - now_M)
        now_M += M - now_M
    else:
        money += ab_i[0] * ab_i[1]
        now_M += ab_i[1]

print(money)

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

AB.sort()
result = 0
num = 0

for i in range(N):
    if num + AB[i][1] <= M:
        num += AB[i][1]
        result += AB[i][0] * AB[i][1]

    else:
        result += AB[i][0] * (M - num)
        break

print(result)

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()
money=0
for i in AB:
    a=i[0]
    b=i[1]
    for j in range(b):
        money+=a
        M-=1
        if M==0:
            break
    if M==0:
        break
print(money)

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

for _ in range(N):
    arr.append(list(map(int, input().split())))

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

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

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

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

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

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

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

li.sort()

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

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

ab.sort()

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

    ans += ab[i][0] * ab[i][1]
    m -= ab[i][1]

Solution (Python):
import bisect

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

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

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

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

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    S = []
    for _ in range(N):
        a, b = map(int, input().split())
        S.append([a, b])

    S = sorted(S, key=lambda x: x[0])
    ans = 0
    for s in S:
        if s[1] >= M:
            ans += s[0] * M
            break
        else:
            ans += s[0] * s[1]
            M -= s[1]

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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(key=lambda x: x[0])

money = 0
goal = M

for i in range(10**5):
    if goal - AB[i][1] > 0:
        goal -= AB[i][1]
        money += AB[i][0] * AB[i][1]
    else:
        money += AB[i][0] * goal
        break

print(money)

Solution (Python):




def main():
  n, req = map(int, input().split())
  stores = [tuple(map(int, input().split())) for _ in range(n)]
  stores.sort(key=lambda x: x[0])
  money = 0
  
  for p, c in stores:
    if req == 0:
      break
    
    c = min(c, req)
    
    money += c * p
    req -= c
  
  print(money)


if __name__ == '__main__':
  main()

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

Solution (Python):
import sys

def solve():
    N,M=map(int,sys.stdin.readline().rstrip().split())
    AB=[]
    for i in range(N):
        a,b=map(int,sys.stdin.readline().rstrip().split())
        AB.append((a,b))
    AB = sorted(AB, key=lambda e:e[0])
    ans=0
    for ab in AB:
        if M <= ab[1]:
            ans += ab[0]*M
            return ans
        else:
            ans += ab[0]*ab[1]
            M -= ab[1]

print(solve())

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

Solution (Python):
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N)))
C = sorted(zip(A, B))
ans = 0
m = M
for a, b in C:
    if m >= b:
        ans += a * b
        m -= b
    else:
        ans += a * m
        break
print(ans)

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

AB = sorted(AB)

kosu = 0
kane = 0
for a,b in AB:
    if kosu + b < M:
        kosu += b
        kane += b*a
    else:
        tmp = M - kosu
        kane += tmp*a
        break

print(kane)

Solution (Python):
from operator import itemgetter

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

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

Solution (Python):

"""
H, W = map(int, input().split())
h, w = map(int, input().split())
print(H*W-h*W-w*H+h*w)
"""

"""
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
ansb = 0
for i in range(n):
    ans = 0
    a = list(map(int, input().split()))
    for k in range(m):
        ans += a[k]*b[k]
    ans += c
    if ans > 0:
        ansb += 1
print(ansb)
"""

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

print(ansnum)

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

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

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

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

A.sort()
res = 0
bought = 0

for a, b in A:
  if bought == M:
    break
  if bought + b <= M:
    res += a * b
    bought += b
  else:
    res += (M - bought) * a
    break

print(res)

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

items = sorted(items, key=lambda x: x[0])
cnt = 0
ans = 0
for item in items:
    a, b = item
    if cnt + b > M:
        tmp = M - cnt
        ans += a * tmp
        print(ans)
        exit()
    else:
        ans += a * b
        cnt += b
    if cnt >= M:
        print(ans)
        exit()

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


ans = 0
while M > 0:
    a, b = Drinks.pop()
    if M > b:
        M -= b
        ans += a * b
    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])
s = 0
c = 0
for i in range(N):
    for j in range(AB[i][1]):
        s += AB[i][0]
        c += 1
        if c >= M:
            print(s)
            exit()

Solution (Python):

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

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

    if m==0:
        break

print(res)

Solution (Python):
n, m = map(int, input().split())
abs = []
for i in range(n):
  a, b = map(int, input().split())
  abs.append({'price': a, 'count': b})
cnt = 0
total_price = 0

for x in sorted(abs, key=lambda x: x['price']):
  if cnt + x['count'] < m:
    cnt += x['count']
    total_price += x['count'] * x['price']
  else:
    total_price += (m - cnt) * x['price']
    break

print(total_price)

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

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

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

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

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

yen = 0
num = 0
for d in Di:
    if num + d[1] >= M:
        yen += (M - num) * d[0]
        break
    num += d[1]
    yen += d[0] * d[1]
print(yen)

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

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

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(key=lambda x:x[0])

num = 0
money = 0
for i in range(n):
    if num+AB[i][1]<m:
        num += AB[i][1]
        money += AB[i][0]*AB[i][1]
    else:
        money += (m-num)*AB[i][0]
        print(money)
        break

Solution (Python):



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

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

Solution (Python):


def main():
    n, m = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(n)]
    count = 0
    data.sort(key=lambda x: x[0])
    ans = 0
    for i in range(n):
        if count + data[i][1] >= m:
            ans += data[i][0] * (m - count)
            break
        else:
            count += data[i][1]
            ans += data[i][0] * data[i][1]
    print(ans)




if __name__ == '__main__':
    main()

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

Solution (Python):
N, M = map(int, input().split())
S = [[0, 0] for i in range(N)]
for i in range(N):
  S[i] = [int(x) for x in input().split()]
S.sort()
money = 0
for s in S:
  money += s[0] * min(s[1], M)
  M -= s[1]
  if M <= 0:
    break
print(money)

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

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

count = 0
amount = 0
for shop in ablst:
    if count + shop[1] < m:
        count += shop[1]
        amount += shop[1] * shop[0]
    else:
        for i in range(shop[1]):
            count += 1
            amount += shop[0]
            if count == m:
                print(amount)
                break
        break

Solution (Python):
def solve(N, M, ABs):
    ABs = sorted(ABs)
    ans = 0
    for a, b in ABs:
        if b < M:
            ans += a * b
            M -= b
        else:
            ans += M * a
            break
    return ans


if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for __ in range(N)]
    print(solve(N, M, ABs))

Solution (Python):
N, M = [int(i) for i in input().split()]
data_ls = list()
for i in range(N):
    data_ls.append([int(i) for i in input().split()])
data_ls = sorted(data_ls, key=lambda x:x[0])
_sum = 0
_sum_price = 0
for (a,b) in data_ls:
    if b > M - _sum:
        _sum_price += a * (M - _sum)
        break
    else:
        _sum_price += a * b
        _sum += b
print(_sum_price)

Solution (Python):
n, m = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
l.sort()
tot = 0
i = 0
while m > 0:
    c = min(l[i][1], m)
    m -= c
    tot += l[i][0] * c
    i += 1
print(tot)

Solution (Python):
n,m = map(int, raw_input().split())
arr = []
for i in xrange(n):
	a,b = map(int, raw_input().split())
	arr.append((a,b))
arr.sort()
ans = 0
ptr = 0
while m > 0:
	ans += min(m,arr[ptr][1])*arr[ptr][0]
	m -= min(m, arr[ptr][1])
	ptr += 1
print ans

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

la = []

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

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

ans = 0
ind = 0


while m > 0:
    if la[ind][1] == 0:
        ind += 1
    else:
        ans += la[ind][0]
        m -= 1
        la[ind][1]  -= 1
        

print(ans)

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

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

Solution (Python):

def main():
    N,M = list(map(int,input().split()))
    a = [0]*N
    b=[0]*N
    for i in range(N):
        a[i],b[i] = list(map(int,input().split()))
    idxs = sorted(range(N),key=lambda x:a[x])
    rest=M
    ans=0
    for idx in idxs:
        ans += min(rest,b[idx])*a[idx]
        rest -= min(rest,b[idx])
        if rest==0:
            break

    print(ans)





if __name__=='__main__':
    main()

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

Solution (Python):
N,M=[int(x) for x in input().split()]
dic={}
for i in range(N):
    A,B=[int(x) for x in input().split()]
    try:
        dic[A]+=B
    except:
        dic[A]=B
        
s_dic=sorted(dic.items(), key=lambda x: x[0])

cost=0
for e in s_dic:
    if M-e[1]<0:
        cost+=e[0]*M
        break
    else:
        M-=e[1]
        cost+=e[0]*e[1]

print(cost)

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

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

ans = 0

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

print(ans)

Solution (Python):



N,M = map(int,input().split())
A = []

ans = 0
for _ in range(N):
    A.append(list(map(int,input().split())))

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

for a in A:
    if a[1] >= M:
        ans += a[0]*M
        break
    else:
        ans += a[0]*a[1]
        M -= a[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])
ans = 0
for a, b in ab:
    ans += min(m, b) * a
    m -= b
    if m <= 0:
        break
print(ans)

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

Solution (Python):
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append(struct(a,b))
l=sorted(l,key=lambda x:x.a)
su=0
for x in l:
  if x.b<m:
    m-=x.b
    su+=(x.a)*(x.b)
  else:
    su+=(x.a)*m
    break
print(su)

Solution (Python):
N,M=[int(i) for i in input().split(" ")]
stores=[]
for j in range(N):
    A,B=[int(i) for i in input().split(" ")]
    stores.append([A,B])

stores=sorted(stores,key=lambda w:w[0])

money=0

while M>0:
    store=stores.pop(0)
    if store[1]>=M:
        money+=store[0]*M
        M=0
    else:
        money+=store[1]*store[0]
        M-=store[1]
print(money)

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

from operator import itemgetter
AB.sort(key=itemgetter(0))
ans = 0
n = M
for a, b in AB:
    if n - b > 0:
        ans += a * b
        n -= b
    else:
        ans += a * n
        break

print(ans)

Solution (Python):
if True:
    n,m=map(int,input().split())
    s=[(0,0) for i in range(n)]
    for i in range(n):
        s[i]=list(map(int,input().split()))
    
else:
    n,m=2,5
    s=[(4,9),(2,4)]
s=sorted(s,key=lambda x: x[0])

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

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

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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000)
import heapq
input=lambda : sys.stdin.readline().rstrip('\n')

n,m=map(int,input().split())
data=[]
for i in range(n):
    a,b=map(int,input().split())
    heapq.heappush(data,(a,b))
cnt=0
cost=0
while True:
    a,b=heapq.heappop(data)
    if cnt+b>=m:
        cost+=(m-cnt)*a
        break
    else:
        cnt+=b
        cost+=a*b
print(cost)

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

for k in range(N):
    if M >= L[k][1]:
        ans += L[k][0]*L[k][1]
        M -= L[k][1]
        if M == 0:
            print(ans)
            exit(0)
    elif M < L[k][1]:
        ans += L[k][0]*M
        print(ans)
        exit(0)

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


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

print(ans)

Solution (Python):


import itertools
import collections
import bisect

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

    ans = 0
    rest = M

    for ab in AB:
        buy_count = min(rest, ab[1])
        ans += ab[0] * buy_count
        rest -= buy_count
        if rest == 0:
            break
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

m = 0
c = 0
for x in X:
    c += x[0]*min(M-m, x[1])
    m += min(M-m, x[1])
    if m == M:
        break
print(c)

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

count = 0
cost = 0
for a, b in lst:
    if count + b > M:
        cost += a * (M - count)
        break
    count += b
    cost += a * b
print(cost)

Solution (Python):

if __name__ == "__main__":
    N, M = [int(i) for  i in input().split()]
    shops = []
    for i in range(N):
        shops.append([int(i) for i in input().split()])
    shops = sorted(shops)
    result = 0
    for price, stock in shops:
        if stock >= M:
            result += price * M
            break
        elif stock < M:
            result += price * stock
            M -= stock
    print(result)

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

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


cost = 0
cnt = M
e_i = 0
while cnt > 0:
    can_buy = min(cnt, e[e_i][1])
    

    cost += can_buy * e[e_i][0]
    e[e_i][1] -= can_buy
    cnt -= can_buy
    if e[e_i][1] == 0:
        e_i += 1

print(cost)

Solution (Python):
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,M=rl()
AB = []
for i in range(N):
    a,b=rl()
    AB.append([a,b])

AB.sort()

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

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
drink=[tuple(map(int,input().split())) for _ in range(N)]
drink.sort(key=lambda x:x[0],reverse=True)
cost=0
cnt=0
while True:
    A,B=drink.pop()
    if cnt+B>=M:
        cost+=A*(M-cnt)
        break
    else:
        cnt+=B
        cost+=A*B
print(cost)

Solution (Python):

n,m =map(int,input().split())
lis = [[int(i)for i in input().split()]for _ in range(n)]
lis =sorted(lis,key=lambda x:x[0])
kane = 0
num = 0
for li in lis:
    if num + li[1] < m:
        kane += li[0]*li[1]
        num += li[1]
    else:
        kane += li[0]*(m-num)
        break
print(kane)

Solution (Python):

"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from io import BytesIO


class dict(dict):
    """ dict() -> new empty dictionary """

    def items(self):
        """ D.items() -> a set-like object providing a view on D's items """
        return dict.iteritems(self)

    def keys(self):
        """ D.keys() -> a set-like object providing a view on D's keys """
        return dict.iterkeys(self)

    def values(self):
        """ D.values() -> an object providing a view on D's values """
        return dict.itervalues(self)


def gcd(x, y):
    """ greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x


range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))

input = lambda: sys.stdin.readline().rstrip('\r\n')


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

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

    a.sort()
    cost = 0
    for ai in a:
        if ai[1] < m:
            cost += ai[1] * ai[0]
            m -= ai[1]
        else:
            cost += ai[0] * m
            break

    print(cost)


if __name__ == '__main__':
    main()

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

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

ans = 0

for i in range(len(L)) :
    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):
from operator import itemgetter

N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for i in range(N)]
money = 0
AB = sorted(AB, key=itemgetter(0,1))

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

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

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

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

print(ans)

Solution (Python):
from collections import defaultdict


def main():
    N, M = [int(q) for q in input().split()]

    AB = [
        [int(q) for q in input().split()]
        for _ in range(N)
    ]
    AB = sorted(AB, key=lambda it: it[0])

    res = 0
    for ai, bi in AB:
        if bi >= M:
            res += ai * M
            print(res)
            return
        res += ai * bi
        M -= bi


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

cnt = 0
ans = 0
i = 0
while cnt < M:
    if AB[i][1] > 0:
        ans += AB[i][0]
        AB[i][1] -= 1
        cnt += 1
    else:
        i += 1
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ab = []
for _ in range(n):
    ab.append(tuple(li()))
    
ab.sort()

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

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

info = sorted(info)

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

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

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

D.sort(key=lambda a: a[0])
ans = 0
num = 0
for price, n in D:
  if num + n >= M:
    ans += price * (M - num)
    break
  ans += price * n
  num += n
print(ans)

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

Solution (Python):
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)