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.



Sample input:
2 5
4 9
2 4


Sample output:
12

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(N)]) #入力する時から気をつける

count = 0
ans = 0
for _ab in ab:
    diff = M - count
    if _ab[1] < diff:
        count += _ab[1]  
        ans += _ab[0] * _ab[1]
    else:
        ans += _ab[0] * diff
        break

print(ans)

Submission status: Accepted

Solution code:
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])
counter = 0
for pair in L:
  if m <= pair[1]:
    counter += pair[0] * m
    print(counter)
    break
  else:
    m -= pair[1]
    counter += pair[0] * pair[1]

Submission status: Accepted

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

Submission status: Accepted

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

    A = []
    B = []
    array = []
    for i in range(n):
        array.append(tuple(map(int, input().split())))
    array_sorted = sorted(array, key=lambda item : (item[0]))

    ans = 0
    num = 0
    for pair in array_sorted:
        capacity = m-num
        if capacity >= pair[1]:
            ans += pair[0]*pair[1]
            num += pair[1]
        else:
            ans += pair[0]*capacity
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]
    AB.sort()
    now=m
    score=0
    for a,b in AB:
        k=min(m,b)
        m-=k
        score+=a*k
        if(m==0):
            print(score)
            return
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

n,m = list(map(int, input().split()))
h = []
for i in range(n):
  a, b = list(map(int, input().split()))
  heapq.heappush(h, (a, b))

ans = 0
remain = m
for i in range(len(h)):
  price, count = heapq.heappop(h)
  if(remain - count <= 0):
    ans += price * remain
    print(ans)
    exit()
  else:
    ans += price * count
    remain -= count

Submission status: Accepted

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

d = 0
ans = 0
for _ab in ab:
    diff = m - d
    if _ab[1] - diff < 0:
        ans += _ab[0]*_ab[1]
        d += _ab[1]
    else:
        ans += _ab[0]*diff
        d += diff

print(ans)

Submission status: Accepted

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

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

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

print(amt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
check = 0
AB.sort()

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

Submission status: Accepted

Solution code:
from operator import itemgetter


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

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

def main():
    b = sorted(a, key=itemgetter(0))
    # print(b)
    m = 0
    cost = 0
    for i in range(N):
        # print(b[i])
        if (m + b[i][1]) <= M:
            m += b[i][1]
            cost += (b[i][0] * b[i][1])
        else:
            cost += (b[i][0] * (M-m))
            return cost
    return cost

print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ary = []
for i in range(n):
	a, b = map(int, input().split())
	ary.append([a,b])
ary.sort()
ans = 0

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

Submission status: Accepted

Solution code:
n, m = (int(x) for x in input().split())
s = sorted(([int(x) for x in input().split()] for _ in range(n)), key=lambda x: x[0])
ans = 0
for a,b in s:
    if m <= b:
        ans += a*m
        break
    else:
        m -= b
        ans += a*b
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

li.sort(key=lambda x:(x[0],x[1]))
cost = 0

while m > 0:
    if li[0][1] > 0:
        cost += li[0][0]
        li[0][1] -= 1
        m -= 1
    else:
        li.pop(0)

print(cost)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
drink = []
for tsumugi in range(n):
    drink.append(list(map(int, input().split())))
    #栄養ドリンクの単価と販売本数をリストの形で保存

drink.sort()
bought = 0
shop = 0
ans = 0
while 1:
    dif = m - bought
    if drink[shop][1] >= dif:
        ans += drink[shop][0] * dif
        break
    else:
        ans += drink[shop][0] * drink[shop][1]
        bought += drink[shop][1]
    shop += 1

print(ans)

Submission status: Accepted

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

list1.sort(key=operator.itemgetter(0))
count_drink = 0
count = 0
last = 0
i = 0
while m > count_drink:
    last = list1[i][1]
    while last > 0:
        if m <= count_drink:
            break
        count += list1[i][0]
        last -= 1
        count_drink += 1
    i += 1

print(count)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]

#print(AB)
rest = M
ans = 0
for a, b in sorted(AB, key=lambda x: x[0]):
	
    if (b < rest):
        ans += a*b
        rest -= b
    else:
        ans += (a*rest)
        break
print(ans)

Submission status: Accepted

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

c=0
y=0

A_B_sorted=sorted(A_B)

for ab in A_B_sorted:
    c+=ab[1]
    y+=ab[0]*ab[1]

    if c>=M:
        print(y-ab[0]*(c-M))
        break

Submission status: Accepted

Solution code:
N, M = map(int, input().strip().split())
#print(N, M)
inventory = []
for i in range(N):
    priceQuantity = list(map(int, input().strip().split()))
    inventory.append(priceQuantity)
#print(inventory)
inventory.sort()
#print(inventory)
total = 0
spent = 0
step = 0
#print(step, total, spent)
#print(inventory)
#print()
while total < M:
    while inventory[step][1] > 0:
        total = total + 1
        spent = spent + inventory[step][0]
        inventory[step][1] = inventory[step][1] - 1
        if total == M:
            break
        #print(step, total, spent)
        #print(inventory)
        #print()
        #time.sleep(.1)
    step = step + 1
    #print(step, total, spent)
    #print(inventory)
    #print()
    #time.sleep(.1)

#print(step, total, spent)
#print(inventory)
#print()
print(spent)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
Drinks=sorted([list(map(int,input().split())) for i in range(N)])
Need=0
for i in Drinks:
    if M <= i[1]:
        Need+=i[0]*M
        break
    if M > i[1]:
        Need+=i[0]*i[1]
        M-=i[1]
print(Need)

Submission status: Accepted

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

pay = 0
to = 0
j = 0
while to < m:
	if to+ab[j][1] <= m:
		to += ab[j][1]
		pay += ab[j][0]*ab[j][1]
		j += 1
	else:
		pay += ab[j][0]*(m-to)
		to = m

print(pay)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
ab = np.empty((n, 2), dtype=np.int64)
for i in range(n):
    ab[i, :] = list(map(int, input().split()))

ab = ab[ab[:, 0].argsort(), :]

money = 0
drink = 0
for i in range(n):
    if drink + ab[i, 1] < m:
        money += ab[i, 0] * ab[i, 1]
        drink += ab[i, 1]
    else:
        next_drink = m - drink
        money += ab[i, 0] * next_drink
        break
print(money)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
shop_dict ={}
for i in range(N):
    price,num = map(int, input().split())
    if  price not in shop_dict:
        shop_dict[price] = num
    else:
        shop_dict[price] += num

shop_dict = sorted(shop_dict.items(), key = lambda x:x[0])

#print(shop_dict)
num_count = 0
money_count = 0
for i in range(N):
    #print(shop_dict[i][1] + num_count)
    if num_count + shop_dict[i][1] >= M:
        print(money_count + (M-num_count) * shop_dict[i][0])
     #   print("OK")
        exit()
    num_count += shop_dict[i][1]
    money_count += shop_dict[i][0] * shop_dict[i][1]

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
total = 0
x = sorted(x)
for i in range(0,n):
    if x[i][1] < m:
        total += x[i][0] * x[i][1]
        m -= x[i][1]
    else:
        total += x[i][0] * m
        break
print(total)

Submission status: Accepted

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

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

bottle = 0
money = 0

for n in range(N):
    bottle += X[n][1]
    money += X[n][0] * X[n][1]

    if bottle >= M:
        money -= (bottle - M) * X[n][0]
        break

print(money)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
b = []
for _ in range(n):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)
c = sorted(zip(a,b))
ans = 0
for i in range(n):
    if m > c[i][1]:
        ans += c[i][0]*c[i][1]
        m -= c[i][1]
    else:
        ans += c[i][0]*m
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for _ in range(N)]
rest = M
ans = 0
for a, b in sorted(AB, key=lambda x: x[0]):
    if (b < rest):
        ans += a*b
        rest -= b
    else:
        ans += (a*rest)
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

l = list(zip(a,b))
l.sort()

c = 0
m_rest = m
for i in range(n):
    d = l[i]
    if m_rest == 0:
        break
    if d[1] <= m_rest:
        c += d[0]*d[1]
        m_rest -= d[1]
    else:
        c += d[0]*m_rest
        m_rest = 0

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    pair = []
    for i in range(N):
        A, B = map(int, input().split())
        pair.append([A, B])
    pair.sort()
    count = 0
    money = 0
    now = 0
    while True:
        if pair[now][1] + count < M:
            money += pair[now][1] * pair[now][0]
            count += pair[now][1]
        else:
            money += (M - count) * pair[now][0]
            break
        now += 1
    print(money)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cost=0
amount=m
for i in range(n):
    if amount>0:
        #print('am:',amount)
        if amount > ab[i][1]:
            cost+=ab[i][0]*ab[i][1]
            amount-=ab[i][1]
        else:
            cost+=ab[i][0]*amount
            break
print(cost)

Submission status: Accepted

Solution code:
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split()))
                 for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)

Submission status: Accepted

Solution code:
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
x.sort(key=lambda x: x[0])
#print(x)
num=0
money=0
for i in range(n):
    num+=x[i][1]
    money+=x[i][1]*x[i][0]
    if num>m:
        money=money-(num-m)*x[i][0]
        break
print(money)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for d in ab:
    if d[1] < m:
        ans += d[0] * d[1]
        m -= d[1]
    else:
        ans += d[0] * m
        break
print(ans)

Submission status: Accepted

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

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

sum_drink = 0
sum_money = 0
num = 0
while True:
    if sum_drink + AB_list[num][1] <= M:
        sum_drink += AB_list[num][1]
        sum_money += AB_list[num][0] * AB_list[num][1]
        num += 1
        if num == N:
            break
    else:
        tmp_drink = M - sum_drink
        sum_money += AB_list[num][0] * tmp_drink
        break

print(sum_money)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
info=[]
for i in range(n):
    cost,maxbuy=map(int,input().split())
    info.append([cost,maxbuy])
info2=sorted(info) #安い順に並び替え
total=0
num=0
i=0
while num<=m:
    if num+info2[i][1]>=m:
        total+=(m-num)*info2[i][0]
        break
    num+=info2[i][1]
    total+=info2[i][0]*info2[i][1]
    i+=1
print(total)

Submission status: Accepted

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

shop.sort()

drink=0
cost=0

for s in shop:
    if drink+s[1]>=M:
        cost+=s[0]*(M-drink)
        break
    drink+=s[1]
    cost+=s[0]*s[1]

print(cost)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M = [int(n) for n in input().split()]
    A = []
    for n in range(N):
        A.append([int(n) for n in input().split()])

    vals = sorted(A, key=lambda x: x[0])
    ret = 0
    for v in vals:
        if v[1] < M:
            M -= v[1]
            ret += v[0] * v[1]
        else:
            print(ret + v[0] * M)
            exit()

Submission status: Accepted

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

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

for aabb in ab:
  if aabb[1] >= m - current_amount:
    answer += aabb[0]*(m-current_amount)
    print(answer)
    break
  else:
    answer += aabb[0]*aabb[1]
    current_amount += aabb[1]

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab_l = sorted([list(map(int,input().split())) for _ in range(n)])
cnt = 0
ans = 0
for i in range(n):
    ans += ab_l[i][0] * min(ab_l[i][1],m-cnt)
    cnt += ab_l[i][1]
    if cnt >= m:
        print(ans)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,M = map(int,input().split())
AB = []
s = 0
ans = 0
for i in range (0,N):
  A,B = map(int,input().split())
  AB.append([A,B])
AB.sort()

for i in range (0,N):
  if s + AB[i][1] >= M:
    ans = ans + (M - s) * AB[i][0]
    print(ans)
    sys.exit()
  s = s + AB[i][1]
  ans = ans + AB[i][0] * AB[i][1]

Submission status: Accepted

Solution code:
import heapq
h = []

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

for i in range(N):
  heapq.heappush(h, tuple(map(int, input().split())))

num = 0
result = 0

while(num < M):
  a, b = heapq.heappop(h)
  buyNum = min(b, M - num)
  num += buyNum
  result += buyNum * a
  
print(result)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
AB=[]
for i in range(n):
  a,b=map(int,input().split())
  AB.append([a,b])
AB=sorted(AB)
i=0
amount=0
cost=0
while True:
  if amount+AB[i][1]<m:
    amount+=AB[i][1]
    cost+=AB[i][0]*AB[i][1]
    i+=1
  else:
    cost+=(m-amount)*AB[i][0]
    print(cost)
    break

Submission status: Accepted

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


value = 0
hold = 0
while hold != M:
    if drink[0][1] == 0:
        drink.pop(0)
    value += drink[0][0]
    hold += 1
    drink[0][1] -= 1
print(value)

Submission status: Accepted

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


ab.sort()

cost = 0
bought = 0
for a, b in ab:
  buy = min(b, m - bought)
  cost += a * buy
  bought += buy
  if bought >= m:
    break

print(cost)

Submission status: Accepted

Solution code:
def main():
    n , m = map(int, input().split(' '))
    df = [list(map(int, input().split(' '))) for _ in range(n)]
    df.sort()
    result = 0
    counter = 0
    i = 0
    while counter < m:
        result += min(m-counter, df[i][1])*df[i][0]
        counter += df[i][1]
        i += 1
    print(result)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,raw_input().split())
AB = [0]*N
for i in range(0,N):
  AB[i] = map(int,raw_input().split())
AB = sorted(AB,key=lambda x: x[0])
con = 0
ans = 0

for i in range(0,N):
  for j in range(0,AB[i][1]):
    con = con + 1
    ans = ans + AB[i][0]
    if con == M:
      break
  else:
    continue
  break
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import itemgetter

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

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

# 安い店から順にドリンクを買い占めていけばよい
AB = zip(A,B)
AB = sorted(AB, key=itemgetter(0))

n_rest_drink = M
idx = 0
spent_money = 0

while n_rest_drink > 0:
    n_purchase = min(n_rest_drink, AB[idx][1])
    spent_money += AB[idx][0] * n_purchase
    n_rest_drink -= n_purchase
    idx += 1

print(spent_money)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort()
    t = 0
    for a, b in ab:
        cnt = min(b, m)
        m -= cnt
        t += (cnt * a)
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
B = []
lis = [list(map(int,input().split())) for _ in range(N)]

lis.sort(key=lambda x:x[0])
num = 0
ans = 0
for i in range(N):
    if lis[i][1]<M-num:
        num += lis[i][1]
        ans += lis[i][0]*lis[i][1]
    else:
        ans += lis[i][0]*(M-num)
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

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

count = m
ans = 0
while count != 0:
    a,b = stores.popleft()
    quantity = min(count,b)
    ans += a*quantity
    count -= quantity
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
Xa={}
ans=0
for i in range(N):
    V,S=map(int,input().split())
    if V in Xa :
        Xa[V] += S
    else :
        Xa[V]=S
Xb=sorted(Xa.items())
for i in range (len(Xb)) :
    M -= Xb[i][1]
    ans += Xb[i][0]*Xb[i][1]
    if M <= 0 :
        ans -= abs(M)*Xb[i][0]
        break
 
print(ans)

Submission status: Accepted

Solution code:
import heapq
N,M = map(int,input().split())
AB = []
for _ in range(N):
  A,B = map(int,input().split())
  heapq.heappush(AB, [A,B])
  
num = 0
ans = 0
while num < M:
  A,B = heapq.heappop(AB)
  if num + B <= M:
    ans += A*B
    num += B
  else:
    ans += A*(M-num)
    num += M-num
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = []

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

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

nokori = M
price = 0

for j in AB_2:
  if nokori <= j[1]:
    price += j[0] * nokori
    break
  else:
    price += j[0] * j[1]
    nokori -= j[1]
  
print(price)

Submission status: Accepted

Solution code:
import sys
import pdb
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,M = map(int, input().split())
    drinks = [tuple(map(int, input().split())) for _ in range(N)]
    drinks.sort()
    bought_cnt = 0
    cur_idx = 0
    ans = 0
    while bought_cnt < M:
        price,cnt = drinks[cur_idx]
        if M-bought_cnt >= cnt:
            bought_cnt += cnt
            ans += cnt*price
        else:
            ans += (M-bought_cnt)*price
            break
        cur_idx += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abList = [list(map(int, input().split())) for _ in range(n)]
abList.sort()
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b < abNum:
        abSum += b * a
        abNum -= b
    else:
        abSum += abNum * a
        break
print(abSum)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abList = [list(map(int, input().split())) for _ in range(n)]
abList.sort()
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
abList = sorted([list(map(int, input().split())) for _ in range(n)])
abSum = 0
abNum = m
for i in range(n):
    ab = abList[i]
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.sort(key = itemgetter(0))
#print(AB)
ans = 0
for i in range(N):
  if AB[i][1] >= M:
    ans += AB[i][0] * M
    print(ans)
    exit()
  else:
    M -= AB[i][1]
    ans += AB[i][0] * AB[i][1]

Submission status: Accepted

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

ans = 0
for price, amount in d:
    if M <= 0:
        break
    k = amount if amount < M else M
    ans += price * k
    M -= k

print(ans)