AtCoder Beginner Contest 121 - Energy Drink Collector

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-----
2 5
4 9
2 4

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


Solutions:
(n, m) = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ab_sorted = sorted(ab, key=lambda x: (x[0], -x[1]))
num = 0
amount_of_money = 0
for i in range(n):
	buy = min(ab_sorted[i][1], m - num)
	num += buy
	amount_of_money += ab_sorted[i][0] * buy
	if num >= m:
		print(amount_of_money)
		return


(N, M) = map(int, input().split())
AB = []
p = 0
for n in range(N):
	AB.append(list(map(int, input().split())))
AB.sort()
for (s, b) in AB:
	p += s * min(M, b)
	M -= min(M, b)
print(p)


(N, M) = map(int, input().split())
tmp = []
ans = 0
for _ in range(N):
	tmp.append(list(map(int, input().split())))
tmp.sort()
i = 0
while M > 0:
	ans += tmp[i][0] * min(M, tmp[i][1])
	M -= tmp[i][1]
	i += 1
print(ans)


f = lambda : [*map(int, input().split())]
(n, m) = f()
c = 0
for (a, b) in sorted((f() for _ in range(n))):
	t = min(b, m)
	c += a * t
	m -= t
print(c)


(N, M, *L) = map(int, open(0).read().split())
C = 0
for (a, b) in sorted(zip(*[iter(L)] * 2)):
	C += a * min(M, b)
	M = max(M - b, 0)
print(C)


(n, m) = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(n)])
(i, ans) = (0, 0)
while ab[i][1] < m:
	m -= ab[i][1]
	ans += ab[i][1] * ab[i][0]
	i += 1
ans += ab[i][0] * m
print(ans)


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


(n, m) = map(int, input().split())
ll = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (p, c) in ll:
	ans += p * min(m, c)
	m -= c
	if m < 1:
		break
print(ans)


(N, M) = map(int, input().split())
cost = 0
for (A, B) in sorted((tuple(map(int, input().split())) for i in range(N)), key=lambda p: p[0]):
	bought = min(M, B)
	cost += A * bought
	M -= bought
print(cost)


(n, m) = map(int, input().split())
P = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 0
for (x, y) in P:
	q = min(m, y)
	ans += x * q
	m -= q
	if m == 0:
		print(ans)
		exit()


import sys
pin = sys.stdin.readline

def main():
	(N, M) = map(int, pin().split())
	d = [list(map(int, pin().split())) for _ in [0] * N]
	d.sort()
	cnt = 0
	ans = 0
	for i in d:
		if M <= cnt + i[1]:
			ans += i[0] * (M - cnt)
			print(ans)
			return
		cnt += i[1]
		ans += i[0] * i[1]
	print(ans)
	return
main()


(N, M) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)])
ans = 0
idx = 0
while M:
	b = min(M, AB[idx][1])
	ans += AB[idx][0] * b
	M -= b
	idx += 1
print(ans)


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


(N, M) = [int(v) for v in input().split(' ')]
d = []
for i in range(N):
	d.append([int(v) for v in input().split(' ')])
total = 0
for (v, n) in sorted(d):
	if M > n:
		total += v * n
		M -= n
	else:
		total += v * M
		break
print(total)


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


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
A = sorted(AB, key=lambda x: x[0])
ans = 0
for i in range(N):
	buy = min(M, A[i][1])
	ans += buy * A[i][0]
	M -= buy
print(ans)


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


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


(N, M) = map(int, input().split(' '))
AB = sorted((list(map(int, input().split())) for _ in range(N)))
Money = 0
for (A, B) in AB:
	x = min(B, M)
	Money += A * x
	M -= x
print(Money)


(N, M) = map(int, input().split())
L = []
for i in range(N):
	A = list(map(int, input().split()))
	L.append(A)
L.sort()
P = 0
for (j, k) in L:
	P += j * min(k, M)
	M -= k
	if M <= 0:
		break
print(P)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
ans = 0
for tab in ab:
	if m < 0:
		break
	ans += min(tab[1], m) * tab[0]
	m -= tab[1]
print(ans)


(N, M) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort()
ans = 0
res = M
for v in X:
	ans += v[0] * min(v[1], res)
	res -= v[1]
	if res <= 0:
		break
print(ans)


(N, M) = map(int, input().split())
AB = []
for i in range(N):
	AB.append(list(map(int, input().split())))
AB.sort()
h = 0
k = 0
i = 0
while h + AB[i][1] < M:
	h += AB[i][1]
	k += AB[i][0] * AB[i][1]
	i += 1
k += AB[i][0] * (M - h)
print(k)


(n, m) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
res = 0
cnt = 0
for (a, b) in AB:
	if cnt + b < m:
		cnt += b
		res += a * b
	else:
		res += a * (m - cnt)
		break
print(res)


(N, M) = map(int, input().split())
l = []
for _ in range(N):
	l.append(list(map(int, input().split())))
sorted_l = sorted(l, key=lambda x: x[0])
ans = 0
count = 0
flag = 0
for i in sorted_l:
	if flag == 1:
		break
	for j in range(i[1]):
		if count >= M:
			flag = 1
			break
		ans += i[0]
		count += 1
print(ans)


(n, m) = [int(v) for v in input().split()]
shop_data = sorted([tuple((int(v) for v in input().split())) for i in range(n)])
cost = 0
for i in shop_data:
	cost += i[0] * min(m, i[1])
	m -= min(m, i[1])
print(cost)


(n, m) = map(int, input().split())
lis = []
for i in range(n):
	lis.append(list(map(int, input().split())))
lis.sort()
ans = 0
for (i, j) in lis:
	ans += i * min(m, j)
	m -= min(m, j)
print(ans)


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


(N, m) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])
ans = 0
for i in range(N):
	ans += L[i][0] * min(m, L[i][1])
	m -= min(m, L[i][1])
print(ans)


(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]
li.sort(reverse=False)
money = 0
for (j, k) in li:
	money += j * min(k, m)
	m -= k
	if m <= 0:
		break
print(money)


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


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
l = sorted(l)
p = 0
d = 0
i = 0
while d < m:
	s = min(l[i][1], m - d)
	d += s
	p += l[i][0] * s
	i += 1
print(p)


(N, M) = map(int, input().split())
AB = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
gokei = 0
for ab in AB:
	if M - cnt > ab[1]:
		gokei += ab[1] * ab[0]
		cnt += ab[1]
	else:
		gokei += (M - cnt) * ab[0]
		cnt += M - cnt
	if cnt == M:
		print(gokei)
		return


(n, m) = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (a, b) in ab:
	ans += a * min(m, b)
	m -= min(m, b)
	if m == 0:
		break
print(ans)


(n, m) = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]
AB.sort()
res = 0
for (a, b) in AB:
	res += a * min(b, m)
	m -= b
	if m < 0:
		break
print(res)


(N, M) = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(N)]
lst = sorted(lst)
(S, cnt) = (0, 0)
for x in lst:
	S += x[0] * min(M - cnt, x[1])
	cnt += min(M - cnt, x[1])
print(S)


(n, m) = map(int, input().split())
a = sorted([list(map(int, input().split())) for _ in range(n)])
pay = 0
i = 0
while m > 0:
	p = min(m, a[i][1])
	m -= p
	pay += p * a[i][0]
	i += 1
print(pay)


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


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
ans = 0
bought = 0
for (a, b) in AB:
	m = min(M - bought, b)
	bought += m
	ans += a * m
print(ans)


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
ans = 0
x = 0
for (val, pon) in A:
	for p in range(pon):
		ans += val
		x += 1
		if x >= M:
			print(ans)
			exit()


(N, M) = map(int, input().split())
list = []
for _ in range(N):
	(a, b) = map(int, input().split())
	list.append([a, b])
list.sort()
ans = 0
for (a, b) in list:
	ans += min(b, M) * a
	M = max(0, M - b)
print(ans)


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


(N, M) = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
ABs.sort()
ans = 0
for (A, B) in ABs:
	ans += A * min(M, B)
	M -= min(M, B)
print(ans)


(n, m) = map(int, input().split())
l = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (a, b) in l:
	if b < m:
		ans += a * b
		m -= b
	else:
		ans += a * m
		break
print(ans)


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


(N, M) = map(int, input().split())
D = sorted([list(map(int, input().split())) for n in range(N)])
ans = 0
num = 0
for (a, b) in D:
	num += b
	ans += a * b
	if M <= num:
		ans -= a * (num - M)
		break
print(ans)


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


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


(N, M) = map(int, input().split())
S = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
ans = 0
for (a, b) in S:
	if M <= 0:
		break
	x = min(M, b)
	ans += a * x
	M -= x
print(ans)


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


(n, m) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
(ans, cnt) = (0, 0)
for (a, b) in AB:
	for i in range(b):
		ans += a
		cnt += 1
		if cnt >= m:
			print(ans)
			exit()


(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 (yen, kosu) in ab:
	if m == 0:
		break
	x = min(kosu, m)
	m -= x
	ans += yen * x
print(ans)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab)
money = 0
for i in ab:
	money += i[0] * min(m, i[1])
	m -= min(m, i[1])
	if m <= 0:
		break
print(money)


(n, k) = map(int, input().split())
a = sorted((tuple(map(int, input().split())) for i in range(n)))
ans = 0
for x in a:
	temp = min(x[1], k)
	ans += temp * x[0]
	k = max(0, k - temp)
print(ans)


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


f = lambda : map(int, input().split())
(n, m) = f()
l = sorted((list(f()) for _ in range(n)))
c = 0
for (a, b) in l:
	if b > m:
		c += a * m
		break
	c += a * b
	m -= b
print(c)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
onedan = 0
for ab in AB:
	buy = min(ab[1], M)
	onedan += buy * ab[0]
	M -= buy
print(onedan)


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


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


(N, m) = map(int, input().split())
A = sorted([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
	cnt += A[i][0] * min(m, A[i][1])
	m -= min(m, A[i][1])
print(cnt)


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
a = [''] * n
for ii in range(n):
	a[ii] = list(map(int, input().split()))
a.sort()
r = 0
for ii in range(n):
	if a[ii][1] >= m:
		r += a[ii][0] * m
		print(r)
		return
	else:
		r += a[ii][0] * a[ii][1]
		m -= a[ii][1]


(n, m) = [int(x) for x in input().split()]
temp_list = sorted([[int(x) for x in input().split()] for _ in range(n)])
ans = 0
for (a, b) in temp_list:
	ans += a * min(b, m)
	m -= b
	if m <= 0:
		break
print(ans)


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(n)]
A.sort()
ans = 0
cnt = 0
for a in A:
	tmp = min(m - cnt, a[1])
	ans += tmp * a[0]
	cnt += tmp
	if cnt >= m:
		break
print(ans)


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: x[0])
ans = 0
for i in range(n):
	(s, t) = l[i]
	if m - t <= 0:
		ans += s * m
		break
	else:
		m -= t
		ans += s * t
print(ans)


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


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


(N, M) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(N)])
i = 0
n = 0
m = 0
while n < M:
	n += L[i][1]
	m += L[i][0] * L[i][1]
	i += 1
print(m + (M - n) * L[i - 1][0])


(n, m) = list(map(int, input().split()))
a = sorted([list(map(int, input().split())) for i in range(n)])
(cnt, ans, j) = (0, 0, 0)
while cnt < m:
	cnt += a[j][1]
	ans += a[j][0] * a[j][1]
	j += 1
print(ans - (cnt - m) * a[j - 1][0])


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


import sys
(n, m) = input().split()
m = int(m)
a = []
i = n = c = 0
a = sorted((tuple(map(int, e.split())) for e in sys.stdin))
while m > 0:
	c += a[i][0] * a[i][1]
	m -= a[i][1]
	i += 1
print(c + m * a[~-i][0])


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


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(n)]
sum = 0
mr = 0
ks = sorted(k)
for i in range(n):
	if ks[i][1] < m - mr:
		sum += ks[i][0] * ks[i][1]
		mr += ks[i][1]
	else:
		sum += ks[i][0] * (m - mr)
		break
print(sum)


(N, M) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab = sorted(ab)
SUM = 0
for i in range(N):
	(a, b) = ab[i]
	x = min(M, b)
	SUM += a * x
	M -= x
	if M == 0:
		break
print(SUM)


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)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])
ans = 0
count = 0
for i in range(N):
	(a, b) = AB[i]
	if M - count <= b:
		c = M - count
		count += c
		ans += a * c
		break
	count += b
	ans += a * b
print(ans)


(N, M) = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
cost = 0
cnt = 0
i = 0
while cnt < M:
	(a, b) = AB[i]
	if M - cnt <= b:
		cost += a * (M - cnt)
		cnt = M
		break
	cost += a * b
	cnt += b
	i += 1
ans = cost
print(ans)


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB)
sum = 0
answer = 0
i = 0
while sum < M:
	plus = min(AB[i][1], M - sum)
	sum += plus
	answer += plus * AB[i][0]
	i += 1
print(answer)


(N, M) = map(int, input().split())
D = sorted([list(map(int, input().split())) for n in range(N)])
mon = 0
num = 0
for n in range(N):
	mon += D[n][0] * D[n][1]
	num += D[n][1]
	if M <= num:
		print(mon - D[n][0] * (num - M))
		break


from itertools import accumulate
(N, M) = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])
sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))
num = 0
ans = 0
index_ = -1
for (a, b) in sAB:
	index_ += 1
	num += b
	if num >= M:
		break
	ans += a * b
if index_ == 0:
	ans += sAB[0][0] * M
else:
	ans += sAB[index_][0] * (M - cum_num[index_ - 1])
print(ans)


(N, M) = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
P.sort()
ans = 0
for (a, b) in P:
	m = min(M, b)
	ans += a * m
	M -= m
print(ans)


(N, M) = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(N)]
xy.sort(key=lambda x: x[0])
(x, y) = [list(i) for i in zip(*xy)]
nokori = M
ans = 0
for i in range(N):
	ans += x[i] * min(y[i], nokori)
	nokori -= y[i]
	if nokori <= 0:
		break
print(ans)


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


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
c = 0
for i in range(n):
	x = min(m, a[i][1])
	c += x * a[i][0]
	m -= x
	if m == 0:
		break
print(c)


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


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted(a, key=lambda x: x[0])
sum = 0
k = 0
for j in range(m):
	if b[k][1] == 0:
		k += 1
	sum += b[k][0]
	b[k][1] -= 1
print(sum)


(N, M) = map(int, input().split())
AB = sorted((tuple(map(int, input().split())) for _ in range(N)))
ans = 0
for (a, b) in AB:
	k = min(b, M)
	ans += k * a
	M -= k
print(ans)


(N, M, *L) = map(int, open(0).read().split())
ans = 0
for (i, j) in sorted(zip(L[::2], L[1::2])):
	ans += i * min(M, j)
	M -= j
	if M <= 0:
		print(ans)
		break


(n, m) = map(int, input().split())
l = []
for _ in range(n):
	l.append(list(map(int, input().split())))
l.sort()
s = 0
i = 0
while m > 0:
	s += min(l[i][1], m) * l[i][0]
	m -= min(l[i][1], m)
	i += 1
print(s)


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


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


(n, m) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort()
ans = 0
for ab in AB:
	t = min(m, ab[1])
	ans += ab[0] * t
	m -= t
print(ans)


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


li = []
(N, M) = list(map(int, input().split()))
for i in range(N):
	(a, b) = list(map(int, input().split()))
	li.append([a, b])
li.sort()
g = 0
s = 0
for i in range(N):
	if li[i][1] + s < M:
		s += li[i][1]
		g += li[i][1] * li[i][0]
	else:
		g += (M - s) * li[i][0]
		print(g)
		return


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


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
payment = 0
for i in ab:
	price = i[0]
	amount = i[1]
	if amount > m:
		amount = m
	m -= amount
	payment += amount * price
	if m == 0:
		break
print(payment)


import numpy as np
(n, m) = map(int, input().split())
A = np.array([list(map(int, input().split())) for _ in range(n)], dtype='int64')
ind = np.argsort(A[:, 0])
A = A[ind]
num = 0
money = 0
for (a, b) in A:
	num += b
	if num < m:
		money += a * b
	else:
		money += a * (b - (num - m))
		break
print(money)


from sys import stdin
(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort()
ans = 0
for (i, j) in l:
	a = min(m, int(j))
	ans += a * int(i)
	m -= a
print(ans)


(n, m) = map(int, input().split())
d = []
c = 0
last = 0
for i in range(n):
	d.append(tuple(map(int, input().split())))
d.sort()
while m > 0:
	(a, b) = d[last]
	c += min(a * b, m * a)
	m -= b
	last += 1
print(c)


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
l.sort()
ans = 0
for i in range(n):
	ans += l[i][0] * min(m, l[i][1])
	m -= l[i][1]
	if m <= 0:
		break
print(ans)


(N, M) = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(N)]
items.sort()
ans = 0
m = 0
for item in items:
	a = min(M - m, item[1])
	m += a
	ans += a * item[0]
print(ans)


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


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
total = 0
for (a, b) in ab:
	num = min(b, m)
	total += a * num
	m -= num
	if m <= 0:
		break
print(total)


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


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


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


(n, m) = map(int, input().split())
ab = []
ans = 0
for i in range(n):
	(a, b) = map(int, input().split())
	ab.append([a, b])
ab.sort()
for (a, b) in ab:
	t = min(b, m)
	ans += t * a
	m -= t
print(ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
a.sort()
s = 0
p = 0
for i in range(n):
	if s + a[i][1] >= m:
		p += (m - s) * a[i][0]
		break
	s += a[i][1]
	p += a[i][0] * a[i][1]
print(p)


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


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


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


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab_s = sorted(ab)
res = m
temp = 0
for i in range(n):
	if res <= ab_s[i][1]:
		temp += res * ab_s[i][0]
		print(temp)
		return
	else:
		temp += ab_s[i][1] * ab_s[i][0]
		res -= ab_s[i][1]


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
x = 0
y = 0
for (i, j) in A:
	if M - x < j:
		y += i * (M - x)
		break
	else:
		x += j
		y += i * j
print(y)


(N, M) = map(int, input().split())
AB = list((list(map(int, input().split())) for i in range(N)))
AB.sort()
ans = 0
i = 0
while M > 0:
	(A, B) = AB[i]
	ans += A * B
	M -= B
	i += 1
ans += M * A
print(ans)


(N, M) = map(int, input().split())
AB = []
for _ in range(N):
	AB.append(list(map(int, input().split())))
AB = sorted(AB)
cnt = 0
ans = 0
for ab in AB:
	if cnt + ab[1] <= M:
		cnt += ab[1]
		ans += ab[0] * ab[1]
	else:
		ans += (M - cnt) * ab[0]
		cnt += M - cnt
		break
print(ans)


(n, m) = map(int, input().split())
mise = []
for i in range(n):
	mise.append(list(map(int, input().split())))
ans = 0
mise.sort()
i = 0
while m > mise[i][1]:
	ans += mise[i][0] * mise[i][1]
	m -= mise[i][1]
	i += 1
ans += m * mise[i][0]
print(ans)


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


(n, m) = map(int, input().split())
d = [tuple(map(int, input().split())) for _ in range(n)]
d.sort()
ans = 0
for (ai, bi) in d:
	if m <= bi:
		ans += ai * m
		break
	ans += ai * bi
	m -= bi
print(ans)


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


(N, M) = map(int, input().split())
xs = [list(map(int, input().split())) for _ in range(N)]
xs = sorted(xs)
ans = 0
m = M
for x in xs:
	c = min(m, x[1])
	ans += x[0] * c
	m -= c
	if c == 0:
		break
print(ans)


(n, m) = map(int, input().split())
L = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for l in L:
	tmp = min(l[1], m)
	ans += l[0] * tmp
	m -= tmp
	if m == 0:
		break
print(ans)


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	(N, M) = LI()
	AB = [LI() for _ in range(N)]
	AB.sort()
	ans = 0
	for (a, b) in AB:
		if M >= b:
			M -= b
			ans += a * b
		else:
			ans += a * M
			break
	print(ans)

def __starting_point():
	resolve()
__starting_point()


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

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

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


(N, M) = map(int, input().split())
drink = [list(map(int, input().split())) for _ in range(N)]
drink = sorted(drink)
ans = 0
for i in range(N):
	for j in range(drink[i][1]):
		ans += drink[i][0]
		M -= 1
		if M == 0:
			print(ans)
			return


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
A = sorted(A, key=lambda x: x[0])
ans = 0
for i in range(n):
	buy = min(m, A[i][1])
	ans += buy * A[i][0]
	m -= buy
print(ans)


(n, m) = map(int, input().split())
ll = []
for i in range(n):
	l = list(map(int, input().split()))
	ll.append(l)
ll.sort()
t = 0
cst = 0
i = 0
while t < m:
	t += ll[i][1]
	cst += ll[i][0] * ll[i][1]
	if t > m:
		cst -= ll[i][0] * (t - m)
	i += 1
print(cst)


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


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


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


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
ans = 0
M_tmp = M
for (i, (Ai, Bi)) in enumerate(AB):
	cnt = min(M_tmp, Bi)
	ans += Ai * cnt
	M_tmp -= cnt
print(ans)


f = lambda : map(int, input().split())
(n, m) = f()
l = []
for _ in range(n):
	l += [tuple(f())]
l.sort()
c = 0
for (a, b) in l:
	if b < m:
		m -= b
		c += a * b
	else:
		c += a * m
		break
print(c)


(N, M) = list(map(int, input().split()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])
ans = 0
cnt = 0
last_cnt = 0
for (a, b) in sAB:
	cnt += b
	if cnt < M:
		ans += a * b
		last_cnt = cnt
	else:
		ans += a * (M - last_cnt)
		break
print(ans)


(N, M) = map(int, input().split())
ls = sorted([tuple(map(int, input().split())) for _ in range(N)])
cnt = 0
ans = 0
for (a, b) in ls:
	if cnt + b >= M:
		ans += a * (M - cnt)
		break
	cnt += b
	ans += a * b
print(ans)


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
while M:
	(a, b) = X.pop()
	buy = min(M, b)
	ans += a * buy
	M -= buy
print(ans)


(N, M) = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(N)]
li.sort()
n = 0
price = 0
for (i, j) in li:
	n += j
	price += i * j
	if n > M:
		price -= i * (n - M)
		break
print(price)


(N, M) = map(int, input().split())
E = []
for i in range(N):
	E.append(list(map(int, input().split())))
E.sort(key=lambda x: x[0])
ans = 0
i = 0
while M > 0:
	(A, B) = E[i]
	ans += A * min(B, M)
	M = max(M - B, 0)
	i += 1
print(ans)


(n, m, *t) = map(int, open(0).read().split())
c = 0
for (a, b) in sorted(zip(t[::2], t[1::2])):
	c += a * min(m, b)
	m = max(0, m - b)
print(c)


(N, M) = map(int, input().split())
drinks = []
for i in range(N):
	drinks.append(tuple(map(int, input().split())))
drinks.sort()
cnt = 0
res = 0
for i in range(N):
	res += (min(cnt + drinks[i][1], M) - cnt) * drinks[i][0]
	cnt += drinks[i][1]
	if cnt >= M:
		break
print(res)


(n, m) = map(int, input().split())
shop = [[int(i) for i in input().split()] for _ in range(n)]
shop = list(sorted(shop, key=lambda x: x[0]))
count = 0
money = 0
for x in shop:
	count += x[1]
	money += x[0] * x[1]
	if count >= m:
		excess = count - m
		money -= x[0] * excess
		break
print(money)


(N, M) = [int(x) for x in input().split()]
S = []
for i in range(N):
	(a, b) = [int(x) for x in input().split()]
	S.append((a, b))
S.sort()
a = 0
s = 0
while M > 0:
	a += S[s][0] * min(S[s][1], M)
	M -= S[s][1]
	s += 1
print(a)


(N, M) = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(N)]
S.sort()
ans = 0
for (a, b) in S:
	if M > b:
		M -= b
		ans += a * b
		continue
	ans += a * M
	break
print(ans)


(n, m) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x = sorted(x)
cost = 0
for i in range(n):
	cost += x[i][0] * min(m, x[i][1])
	m -= x[i][1]
	if m < 1:
		break
print(cost)


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


I = lambda : list(map(int, input().split()))
(n, m) = I()
A = []
for _ in range(n):
	(a, b) = I()
	A += [[a, b]]
A.sort()
s = 0
for (i, j) in A:
	s += i * min(m, j)
	m -= j
	if m <= 0:
		break
print(s)


(n, m) = map(int, input().split())
li = []
for i in range(n):
	(a, b) = map(int, input().split())
	li.append((a, b))
li.sort()
pp = 0
cj = 0
while m > 0:
	cj += min(li[pp][1], m) * li[pp][0]
	m -= min(li[pp][1], m)
	pp += 1
print(cj)


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


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB.sort()
ans = 0
for (i, j) in AB:
	ans += i * min(M, j)
	M -= min(M, j)
print(ans)


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


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort()
sm = 0
c = 0
for l in a:
	if l[1] < m - c:
		c += l[1]
		sm += l[1] * l[0]
	else:
		sm += (m - c) * l[0]
		break
print(sm)


(n, m) = map(int, input().split())
ab = []
for _ in range(n):
	(a, b) = map(int, input().split())
	ab.append((a, b))
ab.sort()
ans = 0
for (a, b) in ab:
	buy = [m, b][0 <= m - b]
	m -= buy
	ans += a * buy
print(ans)


(N, M) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
rm = list(sorted(L))
n = 0
sum = 0
for i in range(M):
	if rm[n][1] == 0:
		n += 1
	rm[n][1] -= 1
	sum += rm[n][0]
print(sum)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cnt = 0
ans = 0
for (a, b) in ab:
	cnt += b
	ans += a * b
	if cnt >= m:
		if cnt > m:
			ans -= a * (cnt - m)
		break
print(ans)


(n, m) = list(map(int, input().split()))
ab_list = [list(map(int, input().split())) for _ in range(n)]
ab_list.sort()
ans = 0
num = 0
for ab in ab_list:
	ans += ab[0] * ab[1]
	num += ab[1]
	if num >= m:
		i_stop = ab_list.index(ab)
		break
diff_num = num - m
ans -= diff_num * ab_list[i_stop][0]
print(ans)


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


(N, M) = [int(i) for i in input().split()]
ab = [[int(j) for j in input().split()] for i in range(N)]
res = 0
ab.sort()
for (a, b) in ab:
	if b < M:
		M -= b
		res += a * b
	else:
		res += a * M
		break
print(res)


(n, m) = map(int, input().split())
dataset = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 0
for data in dataset:
	if m == 0:
		print(ans)
		exit()
	tmp = min(data[1], m)
	ans += tmp * data[0]
	m -= tmp
print(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
for (a, b) in ab:
	buy = min(m, b)
	m -= buy
	ans += a * buy
print(ans)


(n, m) = map(int, input().split())
ab = [[int(i) for i in input().split()] for _ in range(n)]
ab.sort()
ans = 0
for i in ab:
	if i[1] >= m:
		ans += m * i[0]
		print(ans)
		exit()
	else:
		ans += i[1] * i[0]
		m -= i[1]


(n, m) = [int(x) for x in input().split()]
a = sorted([[int(x) for x in input().split()] for _ in range(n)], key=lambda x: x[0])
result = 0
for x in a:
	cnt = min(m, x[1])
	result += x[0] * cnt
	m -= cnt
print(result)


(N, M, *A) = map(int, open(0).read().split())
(*A,) = zip(*[iter(A)] * 2)
A.sort()
ans = 0
for (a, b) in A:
	ans += a * min(b, M)
	M -= min(b, M)
	if M == 0:
		break
print(ans)


import os
import sys

def main():
	(N, M) = list(map(int, input().split()))
	path = []
	for _ in range(N):
		(A, B) = list(map(int, input().split()))
		path.append([A, B])
	path.sort(key=lambda x: x[0])
	ans = [0, 0]
	for p in path:
		if ans[1] + p[1] <= M:
			ans[0] = ans[0] + p[0] * p[1]
			ans[1] += p[1]
		else:
			num = M - ans[1]
			ans[0] = ans[0] + p[0] * num
			ans[1] = ans[1] + num
		if ans[1] == M:
			print(ans[0])
			return

def __starting_point():
	main()
__starting_point()


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


(n, m) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
l.sort(key=lambda x: x[0])
r = m
i = 0
cnt = 0
while r - l[i][1] > 0:
	r -= l[i][1]
	cnt += l[i][0] * l[i][1]
	i += 1
cnt += r * l[i][0]
print(cnt)


(N, M) = map(int, input().split())
l = sorted(list((tuple(map(int, input().split())) for i in range(N))), key=lambda x: x[0])
c = 0
ans = 0
for (v, k) in l:
	ans += min(k, M - c) * v
	c += min(k, M - c)
	if c == M:
		print(ans)
		exit()


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


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


(n, m) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
x.sort()
(p, c) = (0, 0)
for (a, b) in x:
	if c + b <= m:
		p += a * b
		c += b
	else:
		p += a * (m - c)
		c += m - c
		break
print(p)


(N, M) = list([int(n) for n in input().split(' ')])
E = []
for i in range(N):
	tmp = input().split(' ')
	E.append({'price': int(tmp[0]), 'count': int(tmp[1])})
E.sort(key=lambda e: e['price'])
totP = 0
totC = 0
for i in range(len(E)):
	if totC + E[i]['count'] >= M:
		totP += (M - totC) * E[i]['price']
		break
	else:
		totC += E[i]['count']
		totP += E[i]['price'] * E[i]['count']
print(totP)


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sm = 0
cnt = 0
i = 0
while sm != M:
	cnt += A[i][0] * min(A[i][1], M - sm)
	sm += min(A[i][1], M - sm)
	i += 1
print(cnt)


(N, M) = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N)]
AB = sorted(AB)
result = 0
c = M
for (a, b) in AB:
	t = min(c, b)
	c -= t
	result += a * t
print(result)


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)


(N, M) = map(int, input().split())
ss = []
for _ in range(N):
	(a, b) = map(int, input().split())
	ss.append((a, b))
ss.sort()
m = 0
for (a, b) in ss:
	m += a * min(b, M)
	M -= b
	if M <= 0:
		break
print(m)


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


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


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


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

def __starting_point():
	main()
__starting_point()


(n, m) = [int(x) for x in input().split()]
ab = [tuple((int(x) for x in input().split())) for _ in range(n)]
ab.sort()
res = 0
for (a, b) in ab:
	if m <= b:
		res += a * m
		break
	res += a * b
	m -= b
print(res)


(N, M) = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
L.sort(key=lambda x: x[0])
S = 0
for l in L:
	if l[1] >= M:
		S += l[0] * M
		break
	else:
		S += l[0] * l[1]
		M -= l[1]
print(S)


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


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


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	b = list(map(int, input().split()))
	a.append(b)
a.sort(key=lambda x: x[0])
ans = 0
h = 0
for y in a:
	d = y[0]
	e = y[1]
	if h + e > m:
		ans += (m - h) * d
		h += m - h
	else:
		h += e
		ans += d * e
print(ans)


import sys
(N, M) = list(map(int, input().split()))
ls = []
for i in range(N):
	ls.append(list(map(int, input().split())))
ls.sort(key=lambda x: x[0])
ans = 0
for l in ls:
	if l[1] <= M:
		M -= l[1]
		ans += l[0] * l[1]
	else:
		ans += l[0] * M
		break
print(ans)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
	ans += ab[i][0] * ab[i][1]
	cnt += ab[i][1]
	i += 1
print(ans - (cnt - m) * ab[i - 1][0])


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


(N, M) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]
li.sort()
li3 = []
for j in range(len(li)):
	li3.extend([li[j][0]] * li[j][1])
	if len(li3) > M:
		break
print(sum(li3[0:M]))


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


(n, m) = map(int, input().split())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
l.sort(key=lambda x: x[0])
ans = 0
count = 0
for i in range(n):
	k = min(m - count, l[i][1])
	count += k
	ans += k * l[i][0]
print(ans)


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N)]
AB.sort()
ans = 0
for (a, b) in AB:
	k = min(b, M)
	ans += a * k
	M -= k
	if M == 0:
		break
print(ans)


(N, M) = map(int, input().split())
A = sorted([list(map(int, input().split())) for _ in range(N)])
num = 0
ans = 0
for i in range(N):
	flag = False
	val = A[i][0]
	max_num = A[i][1]
	for j in range(max_num):
		ans += val
		num += 1
		if num == M:
			flag = True
			break
	if flag:
		break
print(ans)


(n, m) = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
c = sorted(c)
ans = 0
d = 0
for (a, b) in c:
	if b + d >= m:
		ans += a * (m - d)
		break
	else:
		ans += a * b
		d += b
print(ans)


import sys
(n, m, *l) = map(int, sys.stdin.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


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB_s = sorted(AB)
ans = 0
cnt = 0
for (a, b) in AB_s:
	ans += a * b
	cnt += b
	if cnt >= M:
		ans -= a * (cnt - M)
		print(ans)
		exit()


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
for i in range(M):
	sumcost += A[0][0]
	A[0][1] -= 1
	if A[0][1] < 1:
		A.pop(0)
print(sumcost)


(n, m) = map(int, input().split())
P = [list(map(int, input().split())) for i in range(n)]
P.sort(key=lambda x: x[0])
ans = 0
for p in P:
	if p[1] < m:
		ans += p[0] * p[1]
		m -= p[1]
	else:
		print(ans + p[0] * m)
		exit()


(N, M) = map(int, input().split())
A_B = [tuple(map(int, input().split())) for _ in range(N)]
A_B = sorted(A_B, key=lambda x: x[1], reverse=True)
A_B = sorted(A_B, key=lambda x: x[0], reverse=False)
pay = 0
drink = M
for (A, B) in A_B:
	if drink <= B:
		pay += A * drink
		break
	else:
		pay += A * B
		drink -= B
print(pay)


(n, m) = map(int, input().split())
l = []
for x in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
l = sorted(l)
r = 0
for x in l:
	r += min(m, x[1]) * x[0]
	m -= x[1]
	if m <= 0:
		break
print(r)


(n, m) = map(int, input().split())
dic = {}
for i in range(n):
	(a, b) = map(int, input().split())
	dic.setdefault(a, 0)
	dic[a] += b
nedan = sorted(dic)
ans = 0
for yen in nedan:
	if dic[yen] < m:
		ans += yen * dic[yen]
		m -= dic[yen]
	else:
		ans += yen * m
		break
print(ans)


(N, M) = map(int, input().split())
l = []
for i in range(N):
	(A, B) = map(int, input().split())
	l.append([A, B])
l.sort(key=lambda x: x[0])
i = 0
ans = 0
while M > l[i][1]:
	M -= l[i][1]
	ans += l[i][0] * l[i][1]
	i += 1
ans += l[i][0] * M
print(ans)


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


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


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


(N, M) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]
li = sorted(li, key=lambda x: x[0])
m_sum = 0
for i in li:
	buy = min(M, i[1])
	m_sum += i[0] * buy
	M -= buy
print(m_sum)


(N, M) = map(int, input().split())
AB = []
money = 0
drinks = 0
for i in range(N):
	(A, B) = map(int, input().split())
	AB.append([A, B])
AB.sort()
for i in range(N):
	if 0 < M - drinks < AB[i][1]:
		money += (M - drinks) * AB[i][0]
		break
	elif AB[i][1] <= M - drinks:
		money += AB[i][1] * AB[i][0]
		drinks += AB[i][1]
	else:
		break
print(money)


(N, M) = map(int, input().split())
AB = sorted([tuple(map(int, input().split())) for x in range(N)])
ans = 0
for i in range(N):
	ans += AB[i][0] * max(0, min(AB[i][1], M))
	M -= AB[i][1]
print(ans)


(n, m) = list(map(int, input().split()))
lis = []
ans = 0
for _ in range(n):
	(A, B) = list(map(int, input().split()))
	lis.append((A, B))
lis.sort()
for x in lis:
	(a, b) = x
	if m >= b:
		m -= b
		ans = ans + a * b
	else:
		ans = ans + a * m
		break
print(ans)


(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 < 0:
		break
	ans += A * min(B, M)
	M -= B
print(ans)


(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
ans = 0
for i in range(n):
	a = min(m, li[i][1])
	m -= a
	ans += li[i][0] * a
	if a == 0:
		break
print(ans)


(n, m) = map(int, input().split())
drink = []
for _ in range(n):
	(a, b) = map(int, input().split())
	drink.append((a, b))
drink.sort(reverse=1)
ans = 0
while m > 0:
	(a, b) = drink.pop(-1)
	ans += a * min(m, b)
	m -= b
print(ans)


(n, m) = map(int, input().split())
ts = sorted((tuple(map(int, input().split())) for _ in range(n)))
res = 0
for (a, b) in ts:
	x = min(b, m)
	res += a * x
	m -= x
print(res)


from operator import itemgetter
(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort()
i = 0
ans = 0
while m > 0:
	if ab[i][1] <= m:
		m -= ab[i][1]
		ans += ab[i][0] * ab[i][1]
	else:
		ans += ab[i][0] * m
		m = 0
	i += 1
print(ans)


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

def input_array():
	return list(map(int, input().split()))
(n, m) = input2()
AB = [input_array() for _ in range(n)]
AB = sorted(AB, key=lambda x: x[0])
ans = 0
for i in range(n):
	a = AB[i][0]
	b = AB[i][1]
	if b > m:
		ans += a * m
		break
	elif b == m:
		ans += a * b
		break
	else:
		ans += a * b
	m -= b
print(ans)


(N, M) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
ab.sort()
ans = 0
countM = 0
for (a, b) in ab:
	b = min(b, M - countM)
	a *= b
	ans += a
	countM += b
	if countM == M:
		break
print(ans)


(n, m) = map(int, input().split())
d = [tuple(map(int, input().split())) for i in range(n)]
d.sort()
x = 0
for i in range(len(d)):
	x += d[i][0] * min(d[i][1], m)
	m -= min(d[i][1], m)
	if m == 0:
		break
print(x)


(n, m) = [int(v) for v in input().split()]
drink_list = sorted([[int(v) for v in input().split()] for i in range(n)])
total = 0
for i in drink_list:
	buy = min(m, i[1])
	total += i[0] * buy
	m -= buy
print(total)


(a, b) = map(int, input().split())
c = [list(map(int, input().split())) for i in range(a)]
c = sorted(c, key=lambda x: x[0])
ans = 0
for i in range(a):
	if b == 0:
		break
	elif b >= c[i][1]:
		b -= c[i][1]
		ans += c[i][1] * c[i][0]
	else:
		ans += b * c[i][0]
		break
print(ans)


(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


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


(N, M) = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for _ in range(N)]
ab.sort(key=lambda x: x[0])
ans = 0
for (a, b) in ab:
	m = M
	M = max(M - b, 0)
	ans += a * (m - M)
print(ans)


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


(N, M) = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
money = 0
for (a, b) in AB:
	if M > b:
		money += a * b
		M -= b
	else:
		money += a * M
		break
print(money)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
ans = 0
d = 0
for i in range(n):
	s = min(m - d, ab[i][1])
	ans += ab[i][0] * s
	d += s
	if d == m:
		break
print(ans)


(N, M) = map(int, input().split())
sum = 0
A = [[int(i) for i in input().split()] for j in range(N)]
A.sort()
i = 0
while True:
	if A[i][1] >= M:
		sum += A[i][0] * M
		break
	else:
		sum += A[i][0] * A[i][1]
	M -= A[i][1]
	i += 1
print(sum)


(n, m) = map(int, input().split())
s = [[i for i in map(int, input().split())] for _ in range(n)]
c = 0
for (a, b) in sorted(s):
	c += min(m, b) * a
	m -= b
	if m < 1:
		break
print(c)


(n, m) = map(int, input().split())
drk = [list(map(int, input().split())) for _ in range(n)]
drk.sort()
i = 0
ans = 0
while m > 0:
	(a, b) = drk[i]
	if m >= b:
		ans += a * b
		m = m - b
	else:
		ans += a * m
		m = 0
	i += 1
print(ans)


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


(N, M) = list(map(int, input().split()))
price = [[] for i in range(N)]
for i in range(N):
	(a, b) = list(map(int, input().split()))
	price[i] = [a, b]
price.sort()
m = 0
money = 0
for i in range(N):
	if m + price[i][1] < M:
		money += price[i][0] * price[i][1]
		m += price[i][1]
	else:
		money += price[i][0] * (M - m)
		break
print(money)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
ll = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for (p, c) in ll:
	ans += p * min(m, c)
	m -= c
	if m < 1:
		break
print(ans)


(N, M) = map(int, input().split())
ab = []
for _ in range(N):
	ab.append(list(map(int, input().split())))
ab.sort()
y = d = 0
for i in ab:
	y += i[0] * i[1]
	d += i[1]
	if d >= M:
		print(y - (d - M) * i[0])
		exit()


(a, b, c, d) = (list(map(int, input().split())), [], 0, 0)
for i in range(a[0]):
	b.append(list(map(int, input().split())))
b.sort()
for i in range(a[1]):
	c += b[d][0]
	b[d][1] -= 1
	if b[d][1] == 0:
		d += 1
print(c)


(N, M) = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[0])
money = 0
for (a, b) in AB:
	if b >= M:
		money += a * M
		break
	money += a * b
	M -= b
print(money)


(N, M) = map(int, input().split())
drinks = list()
for i in range(N):
	(a, b) = map(int, input().split())
	drinks.append((a, b))
drinks.sort(key=lambda x: x[0])
ans = 0
while M > 0:
	(a, b) = drinks.pop(0)
	if M <= b:
		ans += a * M
		M = 0
	else:
		ans += a * b
		M -= b
print(ans)


(N, M) = map(int, input().split())
(A, B) = ({}, [])
for i in range(N):
	(a, b) = map(int, input().split())
	A[i] = a
	B.append(b)
A = sorted(A.items(), key=lambda x: x[1])
ans = 0
num = 0
for i in range(N):
	flag = False
	max_num = B[A[i][0]]
	for j in range(max_num):
		ans += A[i][1]
		num += 1
		if num == M:
			flag = True
			break
	if flag:
		break
print(ans)


from collections import deque
(n, m) = map(int, input().split())
l = deque(sorted([list(map(int, input().split())) for i in range(n)]))
money = 0
while m != 0:
	(a, b) = l.popleft()
	t = min(b, m)
	m -= t
	money += a * t
print(money)


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


(n, m) = map(int, input().split())
drinks = sorted([list(map(int, input().split())) for _ in range(n)])
(rest, res) = (m, 0)
for i in range(n):
	buy = min(rest, drinks[i][1])
	res += buy * drinks[i][0]
	rest -= buy
print(res)


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


(N, M) = map(int, input().split())
X = sorted([list(map(int, input().split())) for n in range(N)])
G = 0
D = 0
for m in range(M):
	if D + X[m][1] < M:
		D += X[m][1]
		G += X[m][0] * X[m][1]
	else:
		G += X[m][0] * (M - D)
		print(G)
		return


(N, M) = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
B = sorted(A)
s = 0
m = 0
i = 0
while s < M:
	if B[i][1] > 0:
		m += B[i][0]
		B[i][1] -= 1
		s += 1
	else:
		i += 1
print(m)


(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]
li.sort()
ans = 0
for x in li:
	ans += x[0] * min(m, x[1])
	m -= min(m, x[1])
print(ans)


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

def main():
	(N, M, *AB) = list(map(int, read().split()))
	X = [(a, b) for (a, b) in zip(*[iter(AB)] * 2)]
	X.sort()
	ans = 0
	n = 0
	for (a, b) in X:
		if n + b >= M:
			ans += (M - n) * a
			break
		else:
			ans += a * b
			n += b
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
AB = [[int(i) for i in input().split()] for j in range(n)]
AB.sort()
res = 0
for (a, b) in AB:
	m -= b
	if m >= 0:
		res += a * b
	else:
		m += b
		res += a * m
		break
print(res)


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab, key=lambda x: x[0])
ans = 0
d = 0
i = 0
while d < m:
	ans += ab[i][0] * min(m - d, ab[i][1])
	d += ab[i][1]
	i += 1
print(ans)


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


(N, M) = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(N)]
data.sort()
price = 0
for d in data:
	price += d[0] * min(M, d[1])
	M -= d[1]
	if M <= 0:
		break
print(price)


(n, m) = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]
li.sort()
cnt = ans = 0
for (i, j) in li:
	cnt += j
	if cnt >= m:
		print(ans + i * (m + j - cnt))
		break
	ans += i * j


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


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


(n, m, *l) = map(int, open(0).read().split())
c = 0
for (a, b) in sorted(zip(*[iter(l)] * 2)):
	t = min(b, m)
	c += a * t
	m -= t
print(c)


(n, m) = map(int, input().split())
ab = []
for i in range(n):
	lst = list(map(int, input().split()))
	ab.append(lst)
ab.sort()
cost = 0
now = 0
while m != 0:
	cost += ab[now][0]
	ab[now][1] -= 1
	m -= 1
	if ab[now][1] == 0:
		now += 1
print(cost)