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

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

a.sort()

su = 0
co = 0

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

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

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

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

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

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

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

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

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

buy_num = 0
money = 0
for cur_ab in ab_list:
    a, b = cur_ab[0], cur_ab[1]
    if b < (M - buy_num):
        buy_num += b
        money += a * b
    else:
        money += a * (M - buy_num)
        buy_num = M
        break

print(money)

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

AB = sorted(AB)

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

print(ans)

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

f = []

for _ in range(n):
    
    
    a, b = map(int, input().split(' '))

    f.append((a, b))

f = sorted(f)

ans = 0

for tup in f:
    if m >= tup[1]:
        ans += (tup[0] * tup[1])
        m -= tup[1]
    
    else:
        ans += m * tup[0]
        break

print(ans)

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

list = sorted(list,key=lambda x:x[0],reverse=False)
hon = 0
ans = 0
flag = True
for a,b in list:
    if(flag):
        for i in range(b):
            ans += a
            hon += 1
            if hon==m:
                flag=False
                break;
print(ans)

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

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

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

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

juice = sorted(overall)
count = 0
price = 0
for i in range(len(juice)):
    if count + juice[i][1] <= M:
        price += juice[i][0] * juice[i][1]
        count += juice[i][1]
    else:
        diff = M - count
        price += juice[i][0] * diff
        break
        
print(price)

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

a_list = []
b_list = []

for _ in range(N):
    a,b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    
uni = zip(a_list,b_list)
uni = sorted(uni, key=lambda x:x[0])

a_list, b_list = zip(*uni)

now = 0
money = 0
for a, b in zip(a_list, b_list):
    if M - now < b:
        kau = M -now
        now += kau
        money += a*kau
    else:
        now += b
        money += a*b
        
print(money)

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 i in sorted(D.keys()):
    if M > D[i]:
        ans += i * D[i]
        M -= D[i]
    else:
        ans += i * M
        M -= M
    if M <= 0:
        break
print(ans)

Solution (Python):
import sys



import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, m = ip.IL()
    ab = ip.SILS(n)
    id.S(ab, 0, 0)
    ans = 0
    res = 0
    f = False
    for x in ab:
        for _ in r(x[1]):
            res += 1
            ans += x[0]
            if res == m:
                f = True
                break
        if f:
            break

    print(ans)


main()

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

Solution (Python):
def solve(m,ab):
    ans = 0
    for n in ab:
        if m == 0:
            break
        c = min(m,n[1])
        m -= c
        ans += c * n[0]
    return ans


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])
    print(solve(M,ab))

if __name__ == '__main__':
    main()

Solution (Python):


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

lis = [[0, 0]for i in range(N)]

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

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

tmp = 0
i = -1
cost = 0
while tmp < M:
    i += 1
    tmp += lis[i][1]
    cost += lis[i][0]*lis[i][1]
print(cost-lis[i][0]*(tmp-M))

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

num = 0
cost = 0
for shop in shops:
    if (num + shop[1]) >= m:
        cost += shop[0] * (m - num)
        break
    num += shop[1]
    cost += shop[0] * shop[1]
print(cost)

Solution (Python):
def solve(n, m, price_list):
    rest = m
    price_list.sort()
    ans = 0
    for v, c in price_list:
        if c >= rest:
            ans += (v * rest)
            print(ans)
            exit()
        ans += (v * c)
        rest -= c

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

solve(n, m, price_list)

Solution (Python):
n, m = [int(i) for i in input().split()]
ABs = sorted([[int(i) for i in input().split()] for _ in range(n)])
ans, num = 0, 0
for a, b in ABs:
    ans += a * min(b, m - num)
    num += min(b, m - num)
    if num == m:
        break
print(ans)

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

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

if __name__ == '__main__':
	main()

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

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

count=0
money=0
for i in A:
    if count+i[1]<m:
        count+=i[1]
        money+=i[0]*i[1]
    else:
        while count<m:
            count+=1
            money+=i[0]
    
print(money)

Solution (Python):
""" AtCoder """

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

AB = sorted(AB)

ans = 0
i = 0
while True:
    if M <= AB[i][1]:
        ans += AB[i][0] * M
        print(ans)
        exit()
    ans += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    i += 1

Solution (Python):
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
list = [[0,0]] * n
for i in range(n):
    a,b = input().split()
    list[i] = [int(a),int(b)]
list.sort()
k = 0
ans = 0
while m > 0:
    if m > list[k][1]:
        m -= list[k][1]
        ans += (list[k][0] * list[k][1])
    else:
        ans += (list[k][0] * m)
        m = 0
    k += 1
print(ans)

Solution (Python):
n,m = map(int,input().split())
x = []
for _ in range(n):
  a,b = map(int,input().split())
  x.append([a,b])
sx = sorted(x,key=lambda x:x[0])
money = 0
i = 0
for i in range(n):
  a,b = sx[i]
  if m > b:
    money += a*b
    m -= b
  else:
    money += a*m
    print(money)
    exit()

Solution (Python):
import numpy as np
N,M =list(map(int, input().split()))
shops = []
for i in range(N):
    a,b = list(map(int, input().split()))
    shops.append((a,b))
    
cnt = 0
minp = 0
for shop in sorted(shops):
    if cnt + shop[1] >= M:
        minp += shop[0] * (M-cnt)
        break
    else:
        minp += shop[0] * shop[1]
        cnt += shop[1]
        
print(minp)

Solution (Python):
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
count = 0
AB.sort(key=lambda x:x[0])
cost = 0
for a in AB:
    if M > a[1]:
        cost += a[0] * a[1]
        M -= a[1]
    else:
        cost += a[0] * M
        break
print(cost)

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

stores = []
for _ in range(N):
    stores.append(list(map(int, input().rstrip().split(' '))))
    
stores = sorted(stores, key=lambda x: x[0])

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

print(cost)

Solution (Python):

"""
Created on Sat Mar  9 20:50:37 2019

@author: Yamazaki Kenichi
"""

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

A.sort()
counta = M
i = 0
ans = 0
while counta > 0:
    if A[i][1] < counta:
        ans += A[i][0]*A[i][1]
        counta -= A[i][1]
        i += 1
    else:
        ans += A[i][0]*counta
        counta = 0

print(ans)

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

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

A_B.sort(key=lambda x: x[0])
tmp = 0
ans = 0
for a, b in A_B:
    if tmp + b >= M:
        ans += a * (M - tmp)
        break
    ans += a * b
    tmp += b
print(ans)

Solution (Python):
N,M = map(int,input().split())
AB = []
Buffer = []
for i in range(N):
  Buffer = list(map(int,input().split()))
  AB.append(Buffer)
AB.sort()
cure = 0
count = 0
for i in range(M):
  if AB[cure][1] <= 0:
    cure += 1
  AB[cure][1] -=1
  count += AB[cure][0]
print(count)

Solution (Python):
n,m = map(int,raw_input().split(" "))
a = []
for x in range(n):
  q = map(int,raw_input().split(" "))
  a.append(q)

a.sort(key=lambda a:a[0])

ans = 0
now = 0

for x in range(n):
  if now + a[x][1] >= m:
    ans = ans + a[x][0] * (m-now)
    print ans
    exit(0)
  ans += a[x][0] * a[x][1]
  now += a[x][1]

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

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

print(ans)

Solution (Python):
import sys
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
for a,b in AB:
  p = b if M >= b else M
  ans += a*p
  M -= p
  if M == 0:
    print(ans)
    sys.exit()

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

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

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

gold = 0
for A, B in ABi:
    if M >= B:
        M -= B
        gold += A * B
    else:
        gold += A * M
        break

print(str(gold))

Solution (Python):
n, m = map(int, input().split())
drink=[]
for _ in range(n):
  drink.append(list(map(int, input().split())))
drink.sort(key=lambda x: x[0])
cnt=0
price=0
for d in drink:
  if cnt+d[1]<m:
    price+=d[0]*d[1]
    cnt+=d[1]
  else:
    price+=d[0]*(m-cnt)
    break
print(price)

Solution (Python):
import numpy as np

N,M=list(map(int,input().split()))
A=np.zeros((N,2))

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

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

i=0
count=0
cost=0
while(1):
    if count+B[i][1]<=M:
        count+=B[i][1]
        cost+=B[i][0]*B[i][1]
    elif count+B[i][1]>M:
        add=(M-count)
        count+=add
        cost+=B[i][0]*add
    if count==M:
        break
    i+=1
print(int(cost))

Solution (Python):
n, m = map(int, input().split())
a = []
ans = 0
cnt = 0
for i in range(n):
    x, y = map(int, input().split())
    a.append([x, y])
a.sort()

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

Solution (Python):
def solve(n, m, ps):
    qs = sorted(ps)
    num_bottles = 0
    req_money = 0
    for a, b in qs:
        if num_bottles >= m:
            break
        num_buy = min(m - num_bottles, b)
        req_money += a * num_buy
        num_bottles += b
    return req_money


def main():
    n, m = (int(z) for z in input().split())
    ps = [tuple(int(z) for z in input().split()) for _ in range(n)]
    res = solve(n, m, ps)
    print(res)


if __name__ == "__main__":
    main()

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

cost.sort(key=lambda x:x[0])
count = 0
price = 0
for c in cost:
    if count >= m:
        break
    if count + c[1] <= m:
       price += c[0] * c[1]
       count += c[1]
    else:
       price += c[0] * (m-count)
       count = m
print(price)

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

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)

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

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

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

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

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

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

s = 0
for ab in AB:
    if ab[1] > M:
        s += M*ab[0]
        break
    else:
        s += ab[0]*ab[1]
        M -= ab[1]

print(s)

Solution (Python):
from operator import itemgetter
N, M = map(int, input().split())
drink = []
for i in range(N):
    Ai, Bi = map(int, input().split())
    drink.append([Ai,Bi])

drink.sort(key=itemgetter(0))
yen = 0
m = 0
for n in range(N):
    if drink[n][1]+m < M:
        m += drink[n][1]
        yen += drink[n][0]*drink[n][1]
    else:
        yen += (M-m)*drink[n][0]
        break
print(yen)

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

Solution (Python):
N, M = map(int, input().split())
L = [[int(j) for j in input().split()] for i in range(N)]
L = sorted(L, key=lambda x: x[0])
ans = 0
t = 0
for a, b in L:
    k = min(M - t, b)
    ans += k * a
    t += k
    if t == M:
        break
print(ans)

Solution (Python):
n, m = map(int, input().split())
drink = []
for i in range (n):
    a, b = map(int, input().split())
    drink.append([a, b])
drink.sort(key=lambda x:x[0])
money = 0
store = 0
for i in range(m):
    money += drink[store][0]
    drink[store][1] -= 1
    if drink[store][1] == 0:
        store += 1
print(money)

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

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

Solution (Python):
n,m = map(int, input().split())
shops = sorted([list(map(int,input().split())) for _ in range(n)])
rest = m
ans = 0
while rest > 0:
    shop = shops.pop(0)
    buy = min(rest, shop[1])
    ans += buy*shop[0]
    rest -= buy
print(ans)

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

Solution (Python):


n,m = map(int,raw_input().strip().split())

arr = []

for i in range(n):
    arr.append(list(map(int,raw_input().strip().split())))

arr = sorted(arr)

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

Solution (Python):


import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N, M = [int(x) for x in input().split()]
AB = []
for _i in range(N):
    AB.append([int(x) for x in input().split()])

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

got_num = 0
total_money = 0
for ab in AB:
    price = ab[0]
    num = ab[1]
    if got_num + num <= M:
        total_money += price * num
        got_num += num
    else:
        total_money += price * (M - got_num)
        got_num = M
    if got_num >= M:
        break
print(total_money)

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

inputs.sort()
count = 0
ans = 0
for A, B in inputs:
    if M < B:
        print
        ans += A * M
        break
    else:
        ans += A * B
        M -= B

print(ans)

Solution (Python):

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

N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: x[0])

ans = 0
for a, b in X:
    cnt = min(M, b)
    ans += a*cnt
    M -= cnt

print(ans)

Solution (Python):
import sys

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
num = 0
for a, b in AB:
    if num + b >= M:
        ans += a * (M - num)
        print(ans)
        sys.exit()
    ans += a * b
    num += b

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

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

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

print(ans)

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

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

A.sort(key=lambda x: x[0])
ans = 0
num = 0
i = 0
while True:
    if M - num <= A[i][1]:
        ans += A[i][0] * (M-num)
        num = M
    else:
        ans += A[i][0] * A[i][1]
        num += A[i][1]
        i += 1
    if num == M:
        print(ans)
        break

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

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

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

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 = sorted(arr)

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

print(ans)

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

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


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

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

price = 0
cnt = 0
for info in ab:
    a, b = info
    if cnt + b >= M:
        price += (M-cnt)*a
        break
    else:
        cnt += b
        price += a*b

print(price)

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 = [tuple(map(int, input().split())) for _ in range(N)]
ab.sort(reverse=True)
cnt = 0
money = 0
while True:
    a,b = ab.pop()
    if cnt+b==M:
        money += b*a
        break
    elif cnt+b>M:
        money += (M-cnt)*a
        break
    else: 
        money += b*a
        cnt += b
print(money)

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

Queue = sorted(Data, key=lambda a:a[0])
num = 0
ans = 0
while(M > num):
    q = Queue.pop(0)
    dif = min(q[1], M - num)
    num += dif
    ans += dif*q[0]
print(ans)

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n,m = map(int, input().split())
    aabb = [[0 for _ in range(2)] for _ in range(n)]
    for i in range(n):
        aabb[i][0], aabb[i][1] = map(int, input().split())
    aabb.sort(key=lambda x: x[0])
    count = 0
    for a,b in aabb:
        k = min([m,b])
        count += k*a
        m -= b
        if m <= 0:
            break
    print(count)

Solution (Python):

import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    C = [[A[i], B[i]] for i in range(N)]
    C.sort()
    ans = 0
    i = 0
    while True:
        if C[i][1]<M:
            M -= C[i][1]
            ans += C[i][0]*C[i][1]
        else:
            ans += C[i][0]*M
            break
        i += 1
    print(ans)

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

data = sorted(data)
count = 0
res = 0
for li in data:
  if count + li[1] < M:
    res += li[0]*li[1]
    count += li[1]
  else:
    res += li[0]*(M-count)
    break

print(res)

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

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

ans=0
for s in l:

    if m>s[1]:
        ans+=s[0]*s[1]
        m-=s[1]
    else:
        ans+=s[0]*m
        break
print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


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


def get_list_of_float():
    return [float(f) for f in input().split()]


def get_list_of_char():
    return list(input().strip())


def get_data(n, order=None, **kwargs):
    if not order:
        order = range(len(kwargs))
    it = iter(order)
    var, fn = zip(*sorted(sorted(kwargs.items()), key=lambda _: next(it)))

    rows = []
    for _ in range(n):
        rows.append(input().split())
    columns = zip(*rows)
    exec("global "+", ".join(var)+"\n"+"\n".join(
        v+"=list(map(fn[{}], data[{}]))".format(i, i)
        for i, v in enumerate(var)),
        globals(),
        {"fn": list(fn), "data": list(columns)}
    )
    return



N, M = 0, 0
A, B = [], []


def set_inputs():
    global N, M, A, B
    N, M = get_list_of_int()
    get_data(N, A=int, B=int)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    AB = sorted(zip(A, B))
    ans = 0
    cnt = 0
    for (a, b) in AB:
        if cnt + b <= M:
            ans += a * b
            cnt += b
            continue
        while cnt < M:
            ans += a
            cnt += 1
        break
    print(ans)
    return


if __name__ == '__main__':
    main()