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())
money = 0
li = [list(map(int, input().split())) for _ in range(n)]
li.sort()

for j in range(n):
    shop = li[j]
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

Submission status: Accepted

Solution code:
from operator import itemgetter

n, m = map(int, input().split())
money = 0
li = [list(map(int, input().split())) for _ in range(n)]
li.sort(key=itemgetter(0))

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

Submission status: Accepted

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

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

# リスト内包表記を利用
# #4716613 より早くなるかな？

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
money = 0
li = []

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

while 0 < m:
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

# 再提出 4715718

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
money = 0
li = []

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

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

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)

A, B = zip(*sorted(zip(A, B)))
cost = 0
for i in range(N):
    if M > B[i]:
        cost += A[i] * B[i]
        M -= B[i]
    else:
        cost += A[i] * M
        break

print(cost)

Submission status: Accepted

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

A_B_list = []
for i in range(N):
    A_B = [int(i) for i in input().split()]
    A_B_list.append(A_B)

ans = 0
A_B_list = sorted(A_B_list)

for A_B in A_B_list:
    if M - A_B[-1] > 0:
        ans += A_B[0]*A_B[-1]
        M -= A_B[-1]
    else:
        ans += A_B[0]*M
        break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter
nm = input().split()
n = int(nm[0])
m = int(nm[1])
a_li = []
b_li = []
for i in range(n):
    ab_li = input().split()
    a_li.append(int(ab_li[0]))
    b_li.append(int(ab_li[1]))
ab_connected = sorted(zip(a_li, b_li), key=itemgetter(0))
a_li, b_li = zip(*ab_connected)
item_count = 0
price_count = 0
for i in range(n):
    if item_count < m:
        if b_li[i] <= (m - item_count):
            item_count += b_li[i]
            price_count += a_li[i] * b_li[i]
        else:
            item_needed = 0
            item_needed = m - item_count
            item_count += item_needed
            price_count += item_needed * a_li[i]
    elif item_count == m:
        break
    else:
        print("error")
print(price_count)

Submission status: Accepted

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

store = []

for i in range(n):
  price,stock = map(int,input().split())
  store.append([price,stock])

store.sort()

total_cost = 0
for i in range(n):
  if m > 0:
    buy = min([m,store[i][1]])
    total_cost += buy * store[i][0]
    m -= buy
  else:
    break

print(total_cost)

Submission status: Accepted

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

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

zan = m
money = 0
for shop in sorted(li_shop, key=lambda x: x[0]):
    if zan > shop[1]:
        # すべて買う
        buy = shop[1]
        money += shop[0] * buy
        zan = zan - buy
    else:
        buy = zan
        money += shop[0] * buy
        zan = 0
print(money)

Submission status: Accepted

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

money = 0

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

print(money)

Submission status: Accepted

Solution code:
N,M = (int(_) for _ in input().split())
shops = []
NumberOfEDWillBuy = []
for i in range(N):
    price,stock = (int(_) for _ in input().split())
    shops.append((price,stock))
#map(int,input().split())はmapobjectを返す
#(int(_) for _ in input().split())はgenerator objectを返す
#iteratorしかsorted関数は使えないので、一度priceとstockにアクセスする形にしてshopsを
#generatorのlistにならないようにしている。
NumberOfEDWanted = M
sortedShops = sorted(shops,key = lambda shop:shop[0])
for shop in sortedShops:
    if NumberOfEDWanted < shop[1]:
        NumberOfEDWillBuy.append(NumberOfEDWanted)
        NumberOfEDWanted = 0
    else:
        NumberOfEDWillBuy.append(shop[1])
        NumberOfEDWanted -= shop[1]
sum = 0
for i in range(len(NumberOfEDWillBuy)):
    sum += sortedShops[i][0]*NumberOfEDWillBuy[i]
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a, b = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N):
    a[i], b[i] = (list(map(int, input().split())))
c = []
for i in range(N):
    c.append([a[i],b[i],i])
c = sorted(c, key=lambda x: x[0])
m = 0
cnt = 0
for i in range(N):
    
    cnt += c[i][1]
    m += c[i][0] * c[i][1]
     
    if cnt == M:
        print(m)
        break
    elif cnt > M:
        print(m - c[i][0] * (cnt - M))
        break
    else:
        continue

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A, B = [], []
for _ in range(N):
  a, b = list(map(int, input().split()))
  A.append(a)
  B.append(b)
  
C = sorted(zip(A,B), key=lambda x:x[0])

total=0
i=0
while M>0:
  a = C[i][0]
  b = C[i][1]
  if M<=b:
    total = total + a*M
    M = 0
  else:
    total = total + a*b
    M = M-b
  i+=1
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import itemgetter

def key_func(n):
	return n[0]

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

list_price_and_energydrink = []

for i in range(N):
	A_i, B_i = map(int, input().split())
	list_shop_number_i = [A_i, B_i]
	list_price_and_energydrink.append(list_shop_number_i)

count_number_drink = 0
count_price_drink = 0

list_price_and_energydrink.sort(key=itemgetter(0))

while count_number_drink < M:
	list_minimum_i = list_price_and_energydrink[0]
	
	if count_number_drink + list_minimum_i[1] > M:
		count_price_drink += list_minimum_i[0] * (M - count_number_drink)
		count_number_drink = M
	else:
		count_number_drink += list_minimum_i[1]
		count_price_drink += list_minimum_i[0] * list_minimum_i[1]	
	
	list_price_and_energydrink.remove(list_minimum_i)

print(count_price_drink)

Submission status: Accepted

Solution code:
a = list(map(int, input().split())) 

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

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

botles = 0
sum_money = 0
for j in range(len(money_hon_list)):
    for k in range(money_hon_list[j][1]):
        if botles < int(a[1]):
            sum_money += money_hon_list[j][0]
            botles += 1
        else:
            break

print(sum_money)

Submission status: Accepted

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

X=[]

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import io, sys, atexit, os

import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


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


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


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


mm = 1000000007



def solve ():
	t = 1
	for it in range (t):
		n,m=num()
		x=[]
		for i in range(n):
			l,r=num()
			x.append((l,r))
		x.sort()
		cc=m
		cost=0
		for i in range(n):
			cost+=x[i][0]*min(cc,x[i][1])
			cc-=min(cc,x[i][1])
		print(cost)






if __name__ == "__main__":
	solve ()

Submission status: Accepted

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

A = [0] * N
B = [0] * N

for i in range(N):
    A[i],B[i] = map(int,input().split())
    
arr = [[0]*2 for i in range(N)]
for i in range(N):
    arr[i] = [A[i],B[i]]
    
arr = sorted(arr,key=lambda x:x[0])

count = 0 #今何本買ったか
money = 0 #今何円使ったか
i = 0
while count < M:
    if (count+arr[i][1]) >= (M):
        money += arr[i][0] * (M - count)
        break
    else:
        count += arr[i][1]
        money += arr[i][0] * arr[i][1]
    i += 1

print(money)

Submission status: Accepted

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

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

sortedData = sorted(data, key=lambda a: a[0])
cost = 0
tmpM = 0
for a, b in sortedData:
	if (m - tmpM) >= b:
		cost += a * b
		tmpM += b
	else:
		cost += a * (m-tmpM)
		break

print(cost)

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

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

costs = 0

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

print(costs)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(lambda x:int(x), input().split())
a_list = []
b_list = []
for i in range(n):
    a, b = [int(i) for i in input().split()]
    a_list.append([i, a])
    b_list.append(b)

a_list.sort(key=lambda a: a[1], reverse=False)
count = 0
ans = 0
for i in range(n):
    index = a_list[i][0]
    if (count + b_list[index]) >= m:
        ans += (m - count) * a_list[i][1]
        break
    else:
        count += b_list[index]
        ans += a_list[i][1] * b_list[index]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:



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

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




SET=[[A[i],B[i]]for i in range(N)]
#print(SET)
SET.sort(key=lambda x:x[0])
#print(SET)

total=0
money=0
for i in range(len(SET)):
	for j in range(SET[i][1]):
		if(total>=M):
			print(money)
			exit()
		total+=1
		money+=SET[i][0]
		#print(money,total)
print(money)

Submission status: Accepted

Solution code:
#coding:utf-8

N, M = (int(x) for x in input().split())
l = []

for i in range(N):
	a, b = (int(x) for x in input().split())
	l.append([a,b])
	
l.sort()

ans = 0
count = 0

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

Submission status: Accepted

Solution code:
import numpy as np
N,les=list(map(int,input().split()))
data=np.array([list(map(int,input().split())) for _ in range(N)])
cost=0

t=data[:,0]
for n in np.argsort(data[:,0]):
    if data[n][1]>les:
        cost+=les*data[n][0]
        break
    else:
        les-=data[n][1]
        cost+=data[n][0]*data[n][1]
print(cost)

Submission status: Accepted

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

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

ABs = sorted(ABs, key=lambda t: t[0])

cost = 0
count_drink = 0
for A, B in ABs:
    if count_drink + B >= M:
        cost += A * (M - count_drink)
        break

    cost += A * B
    count_drink += B
print(cost)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
stores = []
for _ in range(N):
  stores.append(tuple(map(int, input().split())))
res = 0
for store in sorted(stores):
  if M <= 0:
    break
  num = min(M, store[1])
  res += num * store[0]
  M -= num
print(res)

Submission status: Accepted

Solution code:
import sys
import numpy as np

n, m = map(float, input().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
lines.sort()
price = 0
for line in lines:
    if m - line[1] > 0:
        price += line[0] * line[1]
        m -= line[1]
    else:
        price += line[0] * m
        break
print(int(price))

Submission status: Accepted

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

price = 0
L = sorted(L, key=lambda x:x[0])
for l in L:
    if M <= l[1]:
        price += l[0] * M
        break
    else:
        price += l[0] * l[1]
        M -= l[1]
        
print(price)

Submission status: Accepted

Solution code:
from sys import stdin

# 店N軒、M本の栄養ドリンク
N, M = [int(x) for x in stdin.readline().rstrip().split()]

# Aは価格、Bは本数
AiBi_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

# 価格でソート
AiBi_list.sort(key=lambda x: (x[0]))

bought_count = 0
fee = 0

for Ai, Bi in AiBi_list:
    want_to_buy_count = M - (bought_count + Bi)
    if want_to_buy_count < 0:
        fee += Ai * (M - bought_count)
        break
    else:
        fee += Ai * Bi
        bought_count += Bi

print(fee)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right

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

N, M = s_inpl()
A, B = [], []
for _ in range(N):
    a, b = s_inpl()
    A.append(a)
    B.append(b)

A_sind = np.argsort(A)
ans = 0
cnt = 0
for i in A_sind:
    cnt += B[i]
    ans += A[i] * B[i]

    if cnt >= M:
        ans -= (cnt - M) * A[i]
        break

print(ans)

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

can = 0 #購入本数
yen = 0 #購入金額


for ab in AB:
  if can + ab[1] <= M: # 店の商品買い占められるなら
    yen += ab[0] * ab[1]
    can += ab[1]
  elif can < M < can + ab[1]:
    yen += (M-can) * ab[0]
    can += ab[1]
    break

print(yen)

Submission status: Accepted

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

AB.sort()
sum = 0

for ab in AB:
    if M <= ab[1]:
        sum += ab[0] * M
        print(sum)
        exit()
    else:
        sum += ab[0] * ab[1]
        M -= ab[1]

Submission status: Accepted

Solution code:
#!/usr/bin/env pyton3

num=input().split()

N = int(num[0])
M = int(num[1])

AB = []

for a in range(1,N+1):
    date = []
    date2 = input().split()

    date.append(int(date2[0]))
    date.append(int(date2[1]))

    AB.append(date)

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

total_num = 0
price = 0


for i in range(1,N+1):
    if total_num < M:
        total_num += AB[i-1][1]
        price += AB[i-1][0] * AB[i-1][1]
        j = i

defference = total_num - M

price -= AB[j-1][0] * defference

print(price)

Submission status: Accepted

Solution code:
class Shop:
    price = 0
    number = 0

    def __init__(self,price,number):
        self.price = price
        self.number = number


n,m = [int(i) for i in input().split()]

shopList = []

for i in range(n) :
    a,b = [int(j) for j in input().split()]
    shopList.append(Shop(a,b))

shopList.sort(key = lambda x: x.price)

cost = 0
total = 0

for i in shopList:
    #print([i.price, i.number])
    if(total + i.number < m):
        cost += i.price * i.number
        total += i.number
    else:
        cost += i.price * (m - total)
        break;

print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

    AB= np.array([list(map(int, list(input().split()))) for _ in range(N)])
    #print(AB)
    #AB = np.array([[4,9],[2,4]])
    AB_sort_by_A = np.sort(AB.view('i8,i8'), order=['f0'], axis=0).view(np.int)

    #print(AB_sort_by_A)
    buyNum = 0
    money = 0
    for i in range(N):
        if buyNum >= M:
            break
        else:
            drinkVal, drinkNum = AB_sort_by_A[i]
            if M - buyNum > drinkNum:
                buyNum += drinkNum
                money += drinkVal * drinkNum
            else:
                money += drinkVal * (M-buyNum)
                break
    print(money)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(Y)

Submission status: Accepted

Solution code:
from operator import itemgetter

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

arr_sort = sorted(arr, key=itemgetter(0))

money = 0
for A,B in arr_sort:
    M -= B
    money += A * B
    if M <= 0:
        print(money + M * A)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Energy Drink Collector
import numpy as np
N, M = map(int, input().split())
AB = np.zeros((N, 2))
for i in range(N):
    AB[i, :] = np.array(list(map(int, input().split())))

AB_sorted = AB[np.argsort(AB[:, 0]), :]

total_drink = 0
total_cash  = 0
for i in range(N):
    if(total_drink + AB_sorted[i, 1] >= M):
        total_cash += (M-total_drink) * AB_sorted[i, 0]
        break
    else:
        total_cash += AB_sorted[i, 1] * AB_sorted[i, 0]
        total_drink += AB_sorted[i, 1]

print(int(total_cash))

Submission status: Accepted

Solution code:
import pdb

def main():
    param = list(map(int, input().split()))

    n = param[0]
    m = param[1]

    data = []
    for i in range(n):
        param = list(map(int, input().split()))
        data.append(param)

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

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

    print(ans)
    
    return

        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
input_line = input()
info = input_line.split()
N = int(info[0])
M = int(info[1])

A_B = []
for i in range(N):
    input_line = input()
    temp = input_line.split()
    a_b = [int(x) for x in temp]
    A_B.append(a_b)

A_B.sort(key=lambda x:x[0])
#print(A_B)
bought = [0, 0] #[money, num]
p = 0
while (bought[1]<M):
    bought[0] += A_B[p][0]*A_B[p][1]
    bought[1] += A_B[p][1]
    if bought[1]>M:
        diff = bought[1]-M
        bought[0] -= A_B[p][0]*diff
        bought[1] -= diff
    p += 1
print(bought[0])

Submission status: Accepted

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

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

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

for i in AB:
    if M <= i[1]:
        sum_money += M * i[0]
        break
    else:
        sum_money += i[1] * i[0]
        M -= i[1]
        
print(sum_money)

Submission status: Accepted

Solution code:
lx = list(map(int,input().split(" ")))
la = []
cnt = 0

for i in range(0, lx[0]):
    la.append(list(map(int,input().split(" "))))

la = sorted(la)

coin = 0
bottle = lx[1]
i = -1
while (bottle > 0 and i < lx[0]-1):
    i += 1
    while (bottle > 0 and la[i][1] > 0):
        coin += la[i][0]
        bottle -= 1
        la[i][1] -= 1

print(coin)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
drinkList = []
for _ in range(N):
    a,b = map(int,input().split())
    drinkList.append((a,b))
drinkList.sort()
neededMoney = 0
for price,num in drinkList:
    buy = min(M,num)
    neededMoney += buy*price
    M -= buy
    if M==0: break
print(neededMoney)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
energy = [[int(_) for _ in input().split()] for _ in range(N)]
energy.sort(key=lambda x: x[0])
Res = 0

for i in energy:
    if M - i[1] > 0:
        M -= i[1]
        Res += i[0] * i[1]
    elif M == i[1]:
        Res += i[0] * i[1]
        break
    else:
        Res += i[0] * M
        break

print(Res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,M = list(map(int,input().split()))

l = [list(map(int,input().split())) for _ in range(N)]
l = sorted(l, key=lambda x:x[0])
a_cnt = 0
b_cnt = 0
for a,b in l:
    if b <= M:
        b_cnt += b
        M -= b
        a_cnt += a*b
    elif b > M and M > 0:
        b_cnt += M
        a_cnt += a*M
        break
    else:
        break
print(a_cnt)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
sets = []
for _ in range(N):
    sets.append(list(map(int,input().split())))
    
def mergesort(sets):
    if len(sets) == 1:
        return [sets[0]]
    else:
        leng = len(sets)
        sets1 = mergesort(sets[:leng//2])
        sets2 = mergesort(sets[leng//2:])
        return merge(sets1,sets2)

def merge(set1,set2):
    i=0
    j=0
    result = []
    for _ in range(len(set1)+len(set2)):
        if i<len(set1) and j<len(set2):
            if set1[i][0] >= set2[j][0]:
                result.append(set2[j])
                j += 1
            elif set2[j][0] > set1[i][0]:
                result.append(set1[i])
                i += 1
        elif i == len(set1):
            result.append(set2[j])
            j += 1
        elif j == len(set2):
            result.append(set1[i])
            i += 1
    return result

def minimummoney(m,sets):
    sets = mergesort(sets)
    rest = m
    cost = 0
    for i in range(len(sets)):
        if rest > sets[i][1]:
            cost += sets[i][0]*sets[i][1]
            rest -= sets[i][1]
            continue
        if 0 < rest and rest <= sets[i][1]:
            cost += rest * sets[i][0]
        break
    return cost

print(minimummoney(M,sets))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    pairs = []
    for i in range(N):
        pairs.append((A[i], B[i]))
    pairs.sort(key=lambda x: x[0])
    ret = 0
    for p, num in pairs:
        if M <= num:
            ret += p * M
            break
        else:
            ret += p * num
            M -= num
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ab.sort(key=lambda x:x[0])
cost = 0
for i in range(n):
    value = ab[i][0]
    num = ab[i][1]
    if num> m:
        cost += value*m
        break
    else:
        cost += value*num
        m -= num
print(cost)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

def energy_drink_collector(M, heap):
    left = M
    ret = 0

    while left:
        ele = heapq.heappop(heap)
        deduct = min(left, ele[1])
        ret += ele[0] * deduct
        left -= deduct

    return ret


if __name__ == "__main__":
    N, M = map(int, input().split())

    heap = []
    for _ in range(N):
        a, b = map(int, input().split())
        heapq.heappush(heap, (a, b))

    result = energy_drink_collector(M, heap)
    print(result)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
shop_list = [0]*N
cost = 0

for i in range(N):
  shop_list[i]=list(map(int,input().split()))
  
shop_list.sort(key= lambda x: x[0])
for A,B in shop_list:
  if B < M:
    M -= B
    cost += A*B
  elif B >= M:
    cost += A*M
    M = 0
  if M==0:
    break

print(cost)

Submission status: Accepted

Solution code:
import sys

n, m = map(int, sys.stdin.readline().split())
matlist = []
for _ in range(n):
    matlist.append(list([int(i) for i in sys.stdin.readline().split()]))
matlist = sorted(matlist, key=lambda x: x[0])

ans = 0
for c, v in matlist:
    if v >= m:
        ans += c * m
        break
    else:
        ans += c * v
        m -= v

print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
# N:売店数
# M:買う数
AB=[]
for i in range(N):
  ab=list(map(int,input().split()))
  AB.append(ab)
#AB[0]:A円，AB[1]:最大B本まで買える

list.sort(AB,key=lambda x:x[0])
#print(AB)

m=0 #買う数
cost=0 #かかる値段
for i in range(N):
 
 if M-m==AB[i][1]:
     m+=AB[i][1]
     cost+=AB[i][0]*AB[i][1]
     break
 elif M-m<AB[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break
         elif m<M:
             cost=cost-AB[i][0]*j
             m=m-j
 else:
      cost+=AB[i][0]*AB[i][1]
      m+=AB[i][1]
    
print(cost)

Submission status: Accepted

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

ABNs = sorted(ABNs)

r = M
newABNs = []
for i in range(len(ABNs)):
	if ABNs[i][1] <= r:
		r -= ABNs[i][1]
		newABNs.append(ABNs[i])
	else:
		newABNs.append([ABNs[i][0],r])
		break
		
#print(newABNs)

ans = 0
for i in range(len(newABNs)):
	ans += (newABNs[i][0]*newABNs[i][1])
	
print(ans)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
T = [tuple(int(x) for x in input().split()) for i in range(N)]

res = 0
for value, num in sorted(T):
  if M >= num:
    res += value*num
    M -= num
  else:
    res += value * M
    break

print(res)

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

cnt = m
cost = 0
for a, b in ab:
    buy = min(cnt, b)
    cnt -= buy
    cost += a*buy
    
print(cost)

Submission status: Accepted

Solution code:
N, M = map(int, input().split(" "))
drinks = []
for i in range(N) :
    drinks.append(list(map(int, input().split(" "))))
    
drinks_s = sorted(drinks, key=lambda x: x[0])

cur = 0
cost = 0
for i in drinks_s :
    if cur + i[1] <= M :
        cur += i[1]
        cost += i[0] * i[1]
    else :
        cost += (M - cur) * i[0]
        break
        
print(cost)

Submission status: Accepted

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

t = sorted(t, key=lambda v: v[0])

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