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())
p_list = []

res = M
total_p = 0
for i in range(N):
    a, b = map(int, input().split())
    p_list.append(a)
    p_list.append(b)

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

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

acou = 0
co_m = M
ab_s = ab[np.argsort(ab[:,0])]

for i in range(N):
    acou += ab_s[i][0] * min(co_m, ab_s[i][1])
    co_m -= min(co_m, ab_s[i][1])
    if co_m == 0:
        break

print(acou)

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


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
ret = 0
que = deque(sorted(LIR(n)))
while m>0:
    a, b = que.popleft()
    ret += min(m, b) * a
    m -= b



print(ret)

Solution (Python):

n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)

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

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

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

Solution (Python):
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)

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

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

c = sorted(ab, key= lambda x:x[0])
s = [0]
for i in range(n):
    s.append(s[i] + c[i][1])
    if s[i] <= m <= s[i+1]:
        stop = i

ans=0
for i in range(stop):
    ans += c[i][0]*c[i][1]
while s[stop] < m:
    ans += c[stop][0]
    s[stop] += 1
print(ans)

Solution (Python):
n,m,*l=map(int,open(0).read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
    ans+=s*min(m,t)
    m-=t
    if m<=0:
        print(ans)
        break

Solution (Python):
if __name__ == '__main__':
    N, M = map(int, input().split())
    
    AB = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    pay = 0

    AB = sorted(AB, key=lambda x:x[0])
    
    for ab in AB:
        if count + ab[1] > M:
            pay += ab[0]*(M - count)
            break
        else:
            count += ab[1]
            pay += ab[0]*ab[1]
    print(pay)

Solution (Python):





from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

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

cnt,can=0,0
for i in range(n):
    if can+a[i][1]<m:
        cnt+=a[i][0]*a[i][1]
        can+=a[i][1]
    else:
        cnt+=a[i][0]*(m-can)
        break
    
print(cnt)

Solution (Python):
import sys

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

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

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

money = 0
now = 0

for p_ in p:
    price = p_[0]
    amount = p_[1]
    if now + amount < M:
        now += amount
        money += price * amount
    else:
        money += price * (M-now)
        print(money)
        sys.exit()

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)
honsu = 0
money = 0
flag = False
for i in range(N):
    if flag:
        break
    count = ab[i][1]
    for k in range(count):
        if honsu == M:
            flag = True
            break
        else:
            money += ab[i][0]
            honsu += 1
print(money)

Solution (Python):

import sys
def input():
	return sys.stdin.readline().strip()

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

AB = []

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

AB.sort()

total = 0
yen = 0
i = 0
while True:
	A = AB[i][0]
	B = AB[i][1]
	if total + B < M:
		yen += A*B
		total += B
		i += 1
	else:
		yen += (M - total)*A
		break
print(yen)

Solution (Python):
n,m = map(int,input().split())
dct = {}
for _ in range(n):
    a,b = map(int,input().split())
    if a in dct:
        dct[a] += b
    else:
        dct[a] = b
dct = sorted(dct.items())
ans,tmp = 0,0
for a,b in dct:
    for _ in range(b):
        if tmp < m:
            ans += a
            tmp += 1
        else:
            print(ans)
            exit()
print(ans)

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

ans = 0
getDrink = 0
keys_sorted = sorted(d.keys())
isFinish = False
for key in keys_sorted:
  if isFinish:
    break
  for i in range(d[key]):
    getDrink += 1
    ans += key
    if getDrink == m:
      isFinish = True
      break
print(ans)

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])
res = 0

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

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

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

j=0
while m>0:
  if m>ab[j][1]:
    cost+=ab[j][0]*ab[j][1]
    m-=ab[j][1]
  else:
    cost+=m*ab[j][0]
    m=0
  j+=1
print(cost)

Solution (Python):
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
  while ab[i][1] > 0 and m> 0:
    m -= 1
    ab[i][1] -= 1
    ans += ab[i][0]
    
print(ans)

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

ab = sorted(ab)
count = 0
total = 0
idx = 0
while True:
    if count >= m:
        total -= (count-m) * ab[idx-1][0]
        break
    total += ab[idx][0] * ab[idx][1]
    count += ab[idx][1]
    idx += 1

print(total)

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

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

p = 0
s = 0
i = 0
while s < m:
    a, b = ls[i]
    if s + b < m:
        s += b
        p += b * a
    else:
        p += (m - s) * a
        break
    i += 1
print(p)

Solution (Python):
import sys

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

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

AB.sort()



total_buttle = 0
total_cost = 0
for _ in range(N):
    total_buttle = total_buttle + AB[_][1]
    if (total_buttle >= M):
        total_cost = total_cost + AB[_][0]*AB[_][1] - AB[_][0]*(total_buttle-M)
        
        
        break

    total_cost = total_cost + AB[_][0]*AB[_][1]


print(total_cost)

Solution (Python):
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

N, M = map(int, input().split())
A = [0]*N
B = [0]*N
l = []
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
    l.append((a, b))
    
l.sort()
ans = 0
for (a, b) in l:
    if b >= M:
        ans += a * M
        break
    else:
        ans += a * b
        M -= b
print(ans)

Solution (Python):
def MAP(): return list(map(int,input().split()))

n,m = MAP()
lst = [MAP() for _ in range(n)]
lst = sorted(lst,key = lambda x:x[0])
q = 0
ans = 0

for i in lst:
    if q+i[1]<m:
        q+=i[1]
        ans+=i[0]*i[1]
    else:
        ans += (m-q)*i[0]
        break

print(ans)

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

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

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

mise.sort()

honnsuu = 0
kinngaku = 0
for a, b in mise:
    if honnsuu >= M:
        break

    kauhonnsuu = M - honnsuu
    kaeruhonnsuu = min(kauhonnsuu, b)
    kinngaku += kaeruhonnsuu * a
    honnsuu += kaeruhonnsuu

print(kinngaku)

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

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

print(money)

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

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

Solution (Python):

import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)


def main():
    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
    i = 0
    while True:
        a = AB[i][0]
        b = AB[i][1]
        logging.debug('a: %d, b: %d' % (a, b))
        while b > 0 and M > 0:
            b -= 1
            M -= 1
            ans += a
            logging.debug('b: %d, M: %d, ans: %d' % (b, M, ans))
        if M == 0:
            break
        else:
            i += 1
    return ans

if __name__ == '__main__':
    print(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])
bought = 0
budget = 0
i = 0
while bought < m:
    buy = min(ab[i][1], m-bought)
    budget += ab[i][0] * buy
    bought += buy
    i += 1

print(budget)

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



for i in range(n):
    
    c=m-x[i][1]
    if c<=0:
        s=0
        for j in range(i+1):
            
            s+=x[j][0]*x[j][1]
        
        print(s+c*x[i][0])
        break
    m=c

Solution (Python):
n,m = map(int,input().split())
C = [list(map(int,input().split())) for i in range(n)]
C.sort()
drinks = 0
price = 0
for i in range(n):
  if drinks+C[i][1] < m:
    drinks += C[i][1]
    price += C[i][0]*C[i][1]
  else:
    price += C[i][0]*(m-drinks)
    print(price)
    exit()

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

Solution (Python):
N, M = map(int, input().split())
ls = []
for i in range(N):
  A, B = map(int, input().split())
  ls += [(A,B)]
ls.sort(key=lambda x:x[0])
count = 0
ans = 0
for x in ls:
  a,b = x
  bcount = 0
  while count<M and bcount<b:
    count += 1
    bcount += 1
    ans += a
  if count==M:
    break
print(ans)

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

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

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

s = 0
for i in range(len(ab)):
    if M - ab[i][1] > 0:
        
        M -= ab[i][1]
        s += ab[i][0] * ab[i][1]
    else:
        for j in range(ab[i][1]):
            
            M -= 1
            s += ab[i][0]
            if M == 0:
                break
        break

print(s)

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

for ab in sorted(AB):
    for i in range(ab[1]):
        if cnt < M:
            ans += ab[0]
            cnt += 1
        else:
            break
    if cnt >= M:
        break

print(ans)

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

AB.sort(key=lambda x: x[0])
s = 0
m = 0
for a, b in AB:
    r = min(M - m, b)
    m += r
    s += r * a
    if m == M:
        break
print(s)

Solution (Python):


import heapq as hq

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

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

while True:
    a,b=hq.heappop(A)
    ans+=(a*min(b,M))
    M-=min(b,M)
    if M==0:
        break
    
print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N, M = map(int, input().split())
    C = [list(map(int, input().split())) for i in range(N)]
    C = sorted(C)
    s = 0
    ans = 0
    
    for i in range(N):
        if s == M:
            break
        ans += C[i][0] * min(M-s,C[i][1])
        s += min(M-s,C[i][1])

    print(ans)
    
    
main()

Solution (Python):

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

l = sorted(l)
j = 0
sum = 0
while M != 0:
    if M - l[j][1] > 0:
        sum = sum + l[j][0] * l[j][1]
        M = M - l[j][1]
    else:
        sum = sum + l[j][0] * M
        M = 0 
    j += 1 
print(sum)

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

    sort_A = sorted(A)
    cnt = 0
    money = 0
    for i in range(N):
        if cnt + sort_A[i][1] >= M:
            money += (M - cnt) * sort_A[i][0]
            break
        money += sort_A[i][0] * sort_A[i][1]
        cnt += sort_A[i][1]

    print(money)

main()

Solution (Python):
from operator import itemgetter

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

shops = sorted(shops, key=itemgetter(0))
rest = m
cost = 0
for a, b in shops:
    if rest > b:
        cost += a * b
        rest -= b
    else:
        cost += a * rest
        break

print(cost)

Solution (Python):
n, m = map(int, input().split())
ans = 0
shop = [tuple(map(int, input().split())) for _ in range(n)]
shop.sort()
for price, num in shop:
    num = min(m, num)
    ans += price * num
    m -= num
print(ans)

Solution (Python):
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
total = [0] * (n + 1)
ans = 0


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

for i in range(1, n + 1):
    a_i, b_i = shop[i - 1]
    
    
    
    b[i] = b[i - 1]
    total[i] = total[i - 1]
    b[i] += b_i
    total[i] += a_i * b_i

    
    a[i] = a_i

for i in range(1, n + 1):
    if m <= b[i]:
        m = m - b[i - 1]
        
        ans = total[i - 1] + a[i] * m
        break
print(ans)

Solution (Python):
n, m = map(int, input().split())
a = [0] * (n + 1)
b = [0] * (n + 1)
price = [0] * (n + 1)
ans = 0

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

for i in range(1, n + 1):
    a_i, b_i = shop[i - 1]
    a[i] = a[i - 1]
    b[i] = b[i - 1]
    price[i] = a_i
    a[i] += a_i * b_i
    b[i] += b_i

for i in range(1, n + 1):
    if m <= b[i]:
        m = m - b[i - 1]
        ans = a[i - 1] + price[i] * m
        break
print(ans)

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

shop.sort()

total = 0
for i in range(len(shop)):
    if shop[i][1] == M:
        total += shop[i][0] * shop[i][1]
        break
    elif shop[i][1] > M:
        total += shop[i][0] * M
        break
    else:
        total += shop[i][0] * shop[i][1]
        M -= shop[i][1]
print(total)

Solution (Python):
import sys
n, m, *b = map(int, sys.stdin.read().split())
a = 0
for p, q in sorted(zip(b[::2],b[1::2])):
  a += p*min(q,m)
  m -= q
  if m <= 0:
    print(a)
    break

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

for _ in range(n):
    yen, num = map(int, input().split())
    shop.append([yen, num])

shop.sort()

ans = 0
for yen, num in shop:
    if num < m:
        ans += yen*num
        m -= num
    else:
        ans += yen*m
        break

print(ans)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
h = []
for _ in range(n):
    a,b = LI()
    heappush(h,(a,b))

cnt = 0
ans = 0
while cnt < m:
    a,b = heappop(h)
    if b + cnt <= m:
        cnt += b
        ans += a*b
    else:
        ans += (m-cnt)*a
        cnt = m
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])
answer = 0
for ab in AB:
    if M - ab[1] <= 0:
        answer += M * ab[0]
        break
    else:
        answer += ab[0] * ab[1]
        M -= ab[1]
print(answer)

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

for i in range(N):
    a, b = ab[i]
    if b + m >= M:
        total = total + (M - m) * a
        break
    else:
        total += b * a
        m += b
print(total)

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

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

AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
ans=0
count = 0
money=0
i=0
while count < M:
    count += AB[i][1]
    if count >= M:
        count -= AB[i][1]
        money+=AB[i][0]*(M-count)
        break
    else:
        money+=AB[i][0]*AB[i][1]
    i+=1
        
print(money)

Solution (Python):
import math
import copy
import fractions
import numpy as np
from functools import reduce



def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList



n, m = map(int, input().split())
data = getSomeInputListInt(n)

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

dataSum = np.zeros(n)

for i in range(n):
    dataSum[i] = dataSorted[i][1]
    if i == 0:
        continue
    else:
        dataSum[i] += dataSum[i-1]

tmpNum = 0
tmpSa = 0
for i in range(n):
    if dataSum[i] >= m:
        tmpNum = i
        if i == 0:
            tmpSa = m
            break
        else:
            tmpSa = m - dataSum[i-1]
            break

ans = 0
for i in range(tmpNum):
    ans += dataSorted[i][0] * dataSorted[i][1]

ans += dataSorted[tmpNum][0] * tmpSa

print(int(ans))

Solution (Python):
from operator import itemgetter
n,m = map(int,input().split())
AB = []
sAB = []

s = 0
c = 0

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

sAB = sorted(AB,key=itemgetter(0))

for i,(a,b) in enumerate(sAB):
    if c + b < m:
        c += b
        s += a*b
    elif c + b >= m:
        for j in range(b):
            if c < m:
                c += 1
                s += a
            else:
                break

print(s)

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

n = 0
ans = 0
i = 0

while n != M:
    if n + B[i] > M:
        ans += (M - n) * A[i]
        n = M
    else:
        ans += A[i] * B[i]
        n += B[i]
    i += 1
print(ans)

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

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

Solution (Python):
from collections import defaultdict

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

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

ans = 0
for k, v in sorted(d.items(), key=lambda x: x[0]):
    if M == 0:
        break
    q = min(v, M)
    M -= q
    ans += k * q

print(ans)

Solution (Python):
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort(reverse = True)
count = 0
ans = 0
while count < m:
  l = ab.pop()
  for i in range(l[1]):
    count += 1
    ans += l[0]
    if count == m:
      break
print(ans)

Solution (Python):
N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst.append([int(s) for s in input().split()])
lst.sort()
count=0
cost=0
for e in lst:
  count+=e[1]
  cost+=e[0]*e[1]
  if(count>=M):
    cost-=e[0]*(count-M)
    break
print(cost)

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

lst.sort()
count=0
cost=0
for e in lst:
  count+=e[1]
  cost+=e[0]*e[1]
  if(count>=M):
    cost-=e[0]*(count-M)
    break
print(cost)

Solution (Python):
N,M = [int(s) for s in input().split()]
pre_lst=[]
for i in range(N):
  pre_lst.append([int(s) for s in input().split()])
lst = sorted(pre_lst, key=lambda x: x[0])
count=0
cost=0
for e in lst:
  count+=e[1]
  cost+=e[0]*e[1]
  if(count>=M):
    cost-=e[0]*(count-M)
    break
print(cost)

Solution (Python):
n, m = map(lambda x: int(x), input().split())
drinks = []
for _ in range(n):
    a, b = map(lambda x: int(x), input().split())
    drinks.append((a, b))
    
sorted_drinks = sorted(drinks, key=lambda x: x[0])

num_drinks = 0
sum_prices = 0
for price, num in sorted_drinks:
    num_drinks += num
    sum_prices += num * price
    if num_drinks > m:
        sum_prices -= (num_drinks - m) * price
        break
    elif num_drinks == m:
        break

print(sum_prices)

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

Solution (Python):
from sys import stdin
def main():
  from builtins import int, list, map, min
  readline = stdin.readline
  n, m = map(int, readline().split())
  data = [list(map(int, readline().split())) for _ in range(n)]
  data.sort(key = lambda x: x[0])
  purchased = 0
  amount = 0
  for a, b in data:
    t = min(m - purchased, b)
    amount += t * a
    purchased += t
    if purchased == m:
      break
  print(amount)
main()

Solution (Python):
from sys import stdin
def main():
  from builtins import int, list, map, min
  readline = stdin.readline
  n, m = map(int, readline().split())
  data = [list(map(int, readline().split())) for _ in range(n)]
  data.sort(key = lambda x: x[0])
  purchased = 0
  amount = 0
  for v in data:
    t = min(m - purchased, v[1])
    amount += t * v[0]
    purchased += t
    if purchased == m:
      break
  print(amount)
main()

Solution (Python):
import sys
import math

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

Solution (Python):
from heapq import heappush, heappop
N, M = map(int, input().split())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    heappush(l, (A, B))
now = 0
ans = 0
for i in range(N):
    a, b = heappop(l)
    if now + b < M:
        now += b
        ans += a * b
    else:
        ans += a * (M - now)
        print(ans)
        exit()
print(ans)

Solution (Python):
def energy_drink_collector(n,m,dic):
    count = 0
    v = 0
    stores = sorted(dic.keys())

    for i in range(n):
        c = stores[i]
        s = dic[c]
        v += s

        if v >= m:
            _s = s - (v - m)
            count += c * _s
            break
        else:
            count += c * s

    return count

if __name__ == '__main__':
    n,m = map(int,raw_input().split())
    a = [0]*n
    b = [0]*n
    dic = {}
    for i in range(n):
        a[i],b[i] = map(int,raw_input().split())
        dic[a[i]] = 0

    for i in range(n):
        dic[a[i]] = dic[a[i]] + b[i]

    print energy_drink_collector(n,m,dic)

Solution (Python):
N,M = map(int,input().split())
list_A = []
list_B = []
for i in range(N):
    A,B = map(int,input().split())
    list_A.append(A)
    list_B.append(B)
lists = list(zip(list_A,list_B))
lists.sort()
num = 0
Sum = 0
for a,b in lists:
    num += b
    if  num > M:
        n = num - M
        b -= n 
        Sum += a * b
        break
    else:
        Sum += a * b
print(Sum)

Solution (Python):
n,m = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
aa = sorted(a, key=lambda x:x[0])
pay = 0
drink = 0
for i in range(n):
    buy = 0
    while buy < aa[i][1]:
        pay += aa[i][0]
        buy += 1
        if drink + buy == m:
            break
    drink += buy
    if drink == m:
        break
print(pay)

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

counter = 0
ans = 0
for i in range(N):

    for j in range(ab[i][1]):
        counter += 1
        ans += ab[i][0]

        if counter >= M:
            print(ans)
            exit()

Solution (Python):
from operator import itemgetter
n, m = map(int, input().split())
abab = [list(map(int, input().split())) for _ in range(n)]
abab.sort(key=itemgetter(0))
y = h = 0
for a, b in abab :
    if h+b < m : y+=a*b ; h+=b
    elif h < m <= h+b : y+=a*(m-h) ; print(y) ; break

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

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

    tot, budget = 0, 0
    for i in range(N):
        if tot + AB[i][1] <= M:
            tot += AB[i][1]
            budget += AB[i][0] * AB[i][1]
            if tot == M:
                return budget
        else:
            budget += (M - tot) * AB[i][0]
            return budget

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

Solution (Python):
N,M = map(int,input().split())
counter = 0
X =[]
for i in range(N):
    A,B = map(int,input().split())
    X.append([A,B])
ansX = sorted(X)
rest = M
ans = 0
for i in range(N):
    if rest <= ansX[i][1]:
        ans +=rest*ansX[i][0]
        rest= 0
        break
    elif rest > ansX[i][1]:
        ans+= ansX[i][1]*ansX[i][0]
        rest-=ansX[i][1]

print(ans)

Solution (Python):
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
cnt = 0
t = 0
for i in ab:
    mi = min(m - cnt, i[1])
    t += i[0] * mi
    cnt += mi
    if cnt == m:
        print(t)
        exit()

Solution (Python):
n, m = [int(x) for x in input().split(' ')]
ab = sorted([[int(x) for x in input().split(' ')] for _ in range(int(n))], key=lambda x: x[0])
res = 0
num = 0
for a, b in ab:
    if num + b >= m:
        print(res + a * (m - num))
        exit()
    else:
        res += a * b
        num += b

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

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

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

    A.sort()
    ans = 0
    for a,b in A:
        if M == 0:
            break
        n = M if M <= b else b
        M -= n
        ans += n * a
    print(ans)

if __name__ == '__main__':
    main()