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: Runtime Error

Solution code:
N,M=map(int,input().split())
store=[]
for _ in range(N):
  store.append([map(int,input().split())])
store.sort(key=lambda x: x[0])
res=0
for i in range(len(store)):
  price=store[i][0]
  num=store[i][1]
  if M>num:
    res+=price*num
    M-=num
  else:
    res+=price*M
    break
print(res)

Submission status: Runtime Error

Solution code:
NM = NM.split()
N = int(NM[0])
M = int(NM[1])

AB = {}
for i in range(N):
  temp = input()
  temp = temp.split()
  AB[int(temp[0])] = int(temp[1])

A_list = list(AB.keys())
A_list.sort()

cost = 0
amount = 0
for i in range(N):
  if amount + AB[A_list[i]] <= M:
    amount += AB[A_list[i]]
    cost += A_list[i]*AB[A_list[i]]
  else:
    print(amount)
    temp = M - amount
    cost += A_list[i]*temp
    break
    
print(cost)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
store=[]
for _ in range(M):
  store.append([map(int,input().split())])
store.sort(key=lambda x: x[0])
res=0
for i in range(len(store)):
  if M-store[i][1]<=0:
    res+=store[i][0]*M
    break
  else:
    res+=store[i][0]*store[i][1]
    M-=store[i][1]
print(res)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
store=[]
for _ in range(M):
  store.append([map(int,input().split())])
sorted(store,key=lambda x: x[0])
res=0
for i in range(len(store)):
  if M-store[i][1]<=0:
    res+=store[i][0]*M
    break
  else:
    res+=store[i][0]*store[i][1]
    M=M-store[i][1]
print(res)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
store=[list(map(int,input().split())) for _ in range(N)]
sorted(store,cmp=lambda x,y:x[0]-y[0] if x[0]!=y[0] else x[1]-y[1])
res=0
for i in range(len(store)):
  if M-store[i][1]<=0:
    res+=store[i][0]*M
    break
  else:
    res+=store[i][0]*store[i][1]
    M=M-store[i][1]
print(res)

Submission status: Runtime Error

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

total = 0
i = 0

while True:
    total += AB[i][1]
    if total < m:
        i += 1
    else:
        break

ans = 0
for j in range(i):
    ans += AB[j][0]*AB[j][1]
ans += (m - sum(AB[p][1] for p in range(0,i))) * AB[i][0]

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(n)])
drink = 0
cost = 0

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(n)])
drink = 0
cost = 0

for i in range(N):
    cost += shops[i][0]*shops[i][1]
    drink += shops[i][1]
    if drink >= m:
        cost -= (drink -m) * shops[i][0]
        break
        
print(cost)

Submission status: Runtime Error

Solution code:
import numpy as np

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

A = np.empty(N)
B = np.empty(N)

for i in range(N):
    INPUT_AB = input()
    A[i] = int(INPUT_AB.split(" ")[0])
    B[i] = int(INPUT_AB.split(" ")[1])

num_drink = 0
drink_price = 0

while num_drink < M:
    price = np.amin(A)
    store_index = np.argmin(A)
    num_drink += B[store_index]
    print(num_drink)
    if num_drink >= M:
        num_drink -= B[store_index]
        while num_drink < M:
            num_drink += 1
            drink_price += price
        
    else:
        drink_price += price * B[store_index]
        A = np.delete(A, store_index)
        B = np.delete(B, store_index)

print(drink_price)

Submission status: Runtime Error

Solution code:
numpy as np

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

A = np.empty(N)
B = np.empty(N)

for i in range(N):
    INPUT_AB = input()
    A[i] = int(INPUT_AB.split(" ")[0])
    B[i] = int(INPUT_AB.split(" ")[1])

num_drink = 0
drink_price = 0

while num_drink < M:
    price = np.amin(A)
    store_index = np.argmin(A)
    num_drink += B[store_index]
    print(num_drink)
    if num_drink >= M:
        num_drink -= B[store_index]
        while num_drink < M:
            num_drink += 1
            drink_price += price
        
    else:
        drink_price += price * B[store_index]
        A = np.delete(A, store_index)
        B = np.delete(B, store_index)

print(drink_price)

Submission status: Runtime Error

Solution code:
 numpy as np

INPUT_1 = input()

N = int(INPUT_1.split(" ")[0])
M = int(INPUT_1.split(" ")[1])

A = np.empty(N)
B = np.empty(N)

for i in range(N):
    INPUT_AB = input()
    A[i] = int(INPUT_AB.split(" ")[0])
    B[i] = int(INPUT_AB.split(" ")[1])

num_drink = 0
drink_price = 0

while num_drink < M:
    price = np.amin(A)
    store_index = np.argmin(A)
    num_drink += B[store_index]
    print(num_drink)
    if num_drink >= M:
        num_drink -= B[store_index]
        while num_drink < M:
            num_drink += 1
            drink_price += price
        
    else:
        drink_price += price * B[store_index]
        A = np.delete(A, store_index)
        B = np.delete(B, store_index)

print(drink_price)

Submission status: Runtime Error

Solution code:
 numpy as np

INPUT_1 = input()

N = int(INPUT_1.split(" ")[0])
M = int(INPUT_1.split(" ")[1])

A = np.empty(N)
B = np.empty(N)

for i in range(N):
    INPUT_AB = input()
    A[i] = int(INPUT_AB.split(" ")[0])
    B[i] = int(INPUT_AB.split(" ")[1])

num_drink = 0
drink_price = 0import

while num_drink < M:
    price = np.amin(A)
    store_index = np.argmin(A)
    num_drink += B[store_index]
    print(num_drink)
    if num_drink >= M:
        num_drink -= B[store_index]
        while num_drink < M:
            num_drink += 1
            drink_price += price
        
    else:
        drink_price += price * B[store_index]
        A = np.delete(A, store_index)
        B = np.delete(B, store_index)

print(drink_price)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB = sorted(AB)
AB = list(map(list, zip(*AB)))
if N == 1:
    print(AB[0][0] * M)
    
else:
    i = 0
    sumtmp = 0
    while sumtmp <= M:
        sumtmp += AB[1][i]
        i += 1
    if i == 1:
        print(AB[0][0] * M)
    else:
        idx = i - 1
        ans = sum([AB[0][i] * AB[1][i] for i in range(0, idx)])
        ans += AB[0][idx] * (M - sum(AB[1][:idx]))
        print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(N):
    AB.append(list(map(int, input().split())))
    
AB = sorted(AB)
AB = list(map(list, zip(*AB)))
if N == 1:
    print(AB[0][0] * M)
    
else:
    i = 0
    sumtmp = 0
    while sumtmp <= M:
        sumtmp += AB[1][i]
        i += 1
    idx = i - 1
    ans = sum([AB[0][i] * AB[1][i] for i in range(0, idx)])
    ans += AB[0][idx] * (M - sum(AB[1][:idx]))
    print(ans)

Submission status: Runtime Error

Solution code:
list1 = raw_input().split()

N = long(list1[0])

M = long(list1[1])

AB_list = []

for n in range(N):
    item = raw_input().split()
    AB_list.append(item)

AB_list.sort()

money = 0
drink = 0


for x in range(N):
    for b in range(long(AB_list[x][1])):
        money += long(AB_list[x][0])
        drink += 1
        if drink >= M:
            break
    if drink >= M:
        break

prlong money

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
a.sort()
pm = s = 0
m_minus_1 = m - 1
for item in a:
    pm += item[1]
    if tmp > m_minus_1:
        print(s + item[0] * (m - pm + item[1]))
        break
    else:
        s += item[0] * item[1]

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

N,M = map(int,input().split())
store = []
for i in range(N):
  store.append([int(_) for _ in input().split()])
store=store.sort(key=itemgetter(0))

price = 0
for i in range(N):
  if store[i][1]>=M:
    price += store[i][0]*M
    sys.exit()
  else:
    price += store[i][0]*M
    M = M-store[i][1]

Submission status: Runtime Error

Solution code:
def quicksort(lst):
	if lst == []: return []
	elif len(lst) == 1: return lst
	else:
		pivot = lst[0][0]
		leftlist = []
		rightlist = []
		for i in range(0, len(lst)):
			if lst[i][0] < pivot:
				leftlist.append(lst[i])
			else:
				rightlist.append(lst[i])
		newleft = quicksort(leftlist)
		newright = quicksort(rightlist)
		newleft.extend(newright)
		return newleft

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = quicksort(drinklist)

sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

Submission status: Runtime Error

Solution code:
def quicksort(lst):
	if lst == []: return []
	elif len(lst) == 1: return lst
	else:
		pivot = lst[0][0]
		leftlist = []
		rightlist = []
		for i in range(0, len(lst)):
			if lst[i][0] < pivot:
				leftlist.append(lst[i])
			else:
				rightlist.append(lst[i])
		newleft = quicksort(leftlist)
		newright = quicksort(rightlist)
		newleft.extend(newright)
		return newleft

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = quicksort(drinklist)
print drinklist
sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

Submission status: Runtime Error

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

sorted_ab = sorted(AB)
cost = 0
while M > 0:
    for i in range(N):
        for j in range(sorted_ab[i][1]):
            M -= 1
            cost += sorted_ab[i][0]
print(cost)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m=[int(i) for i in input().split(' ')]
class P:
  def __init__(self, a, b)
  	self.a = a
    self.b = b

p = []
for i in range(n):
  a,b=[int(i) for i in input().split(' ')]
  p.append(P(a, b))

  
mon = 0
p.sort(key=lambda x: x.a)
for e in p:
  if m <= e.b:
    mon += e.q * m
    m = 0
  else:
    m -= e.b
    mon += e.a * e.b

print(mon)

Submission status: Runtime Error

Solution code:
n, m = [int(i) for i in input().split()]
dat = [[int(i) for i in input().split()] for i in range(n)]
sort(dat)
sum = 0
_m = 0
for i in dat:
    _m += dat[1]
    if _m > m:
        print(sum + dat[0]*(m - _m))
        break
    sum += dat[0] * dat[1]

Submission status: Runtime Error

Solution code:
import numpy as np
import bisect

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

drinks.sort(key = lambda x: x[0])
prices = np.array([x[0] for x in drinks])
vols = np.array([x[1] for x in drinks])
cum_vols = np.cumsum(vols)
idx = bisect.bisect_right(cum_vols, m) #このidxは1 ~ vols[idx]を使う

vols[idx] = m - sum(vols[:idx])
print(np.dot(vols[:(idx+1)], prices[:(idx+1)]))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
    A_next, B_next = map(int,input().split())
    A.append(A_next)
    B.append(B_next)
shop = list(zip(A,B))
shop.sort(key=lambda x:x[0])
def count(i,M):
    if(M==0):
        return 0
    elif(shop[i][1]<=M):
        return count(i+1,M-shop[i][1])+shop[i][0]*shop[i][1]
    else:
        return M*shop[i][0]
a = count(0,M)
print(a)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
    A_next, B_next = map(int,input().split())
    A.append(A_next),B.append(B_next)
shop = list(zip(A,B))
shop.sort(key=lambda x:x[0])
def count(i,M):
    if(M==0):
        return 0
    elif(shop[i][1]<=M):
        return count(i+1,M-shop[i][1])+shop[i][0]*shop[i][1]
    else:
        return M*shop[i][0]
a = count(0,M)
print(a)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
    A_next, B_next = map(int,input().split())
    A.append(A_next),B.append(B_next)
shop = list(zip(A,B))
shop.sort(key=lambda x:x[0])
def count(i,M):
    if(M==0):
        return 0
    elif(shop[i][1]<=M):
        return count(i+1,M-shop[i][1])+shop[i][0]*shop[i][1]
    else:
        return M*shop[i][0]
count(0,M)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

N,M = map(int,input().split())
AB =defaultdict(list)
total = 0
for _ in range(N):
    A,B = map(int,input().split())
    AB[A].append(B)
while M > 0:
    minAB = AB[min(AB)]
    if minAB[0] <= M:
        #print('あと{}'.format(M))
        M -= minAB[0]
        total += min(AB) * minAB[0]
        del AB[min(AB)]
    else:
        #print('残り{}'.format(M))
        total += min(AB) * M
        M -= M
print(total)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
dict1 = {}
for i in range(n):
    a,b = map(int,input().split())
    dict1[a] = b

dict1_sorted = sorted(dict1.items(),key = lambda x:x[0],reverse = False)

money = 0
count = 0

while m > 0:
    if m > dict1_sorted[count][1]:
        money += dict1_sorted[count][0] * dict1_sorted[count][1]
        m -= dict1_sorted[count][1]
        count += 1
    else:
        money += dict1_sorted[count][0] * m
        m = 0
        count += 1

print(money)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict[A] = B
  A_list.append(A)

A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]
    
    if M == b_accum:
		
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    
print(all_pay)

Submission status: Runtime Error

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

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

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

print(ans)

Submission status: Runtime Error

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[1][i]])
    total_cost += buy * store[0][i]
    m -= buy
  else:
    break

print(total_cost)

Submission status: Runtime Error

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

Solution code:
import copy as cp

N, M = map(int, input().split())
Drink = list(range(2))
Shop_list = list()
L = list()
MED = 0
stack = 0
j = 0
flag = 0

for i in range(N):
    A, B = input().split()
    Drink[0] = int(A)
    Drink[1] = int(B)
    L = cp.deepcopy(Drink)
    Shop_list.append(L)

if N == 1:
    MED = Drink[0]*Drink[1]
    flag = 1
Shop_list.sort()

while stack <= M and flag != 1:
    stack = stack + Shop_list[j][1]
    MED = Shop_list[j][1]*Shop_list[j][0] + MED
    if stack > M:
        loss = stack - M
        MED = MED - loss*Shop_list[j][0]
        break
    j += 1
print(MED)

Submission status: Runtime Error

Solution code:
import sys
 
stdin = sys.stdin

N,Q = map(int,input().split())
S = input()

check_point = []
inf = 10 ** 18

# AC文字列のAの位置をリストに収めた
for i in range(inf):
  out = S.find('AC')
  if out < 0:
    break
  else:
    S = S[out+2:]
    check_point.extend([(out + len(check_point) * 2)])
  

# 指定した文字列範囲を含む要素数を表示
for i in range(Q):
  start, end  = map(int, stdin.readline().split())
  print(len([i for i in check_point if (start - 1 <= i) and (i + 1 < end)]))

Submission status: Runtime Error

Solution code:
import copy as cp

N, M = map(int, input().split())
A = list(range(N))
B = list(range(N))
Drink = list(range(2))
Shop_list = list()
L = list()
MED = 0
stack = 0
j = 0
flag = 0

for i in range(N):
    A, B = input().split()
    Drink[0] = int(A)
    Drink[1] = int(B)
    L = cp.deepcopy(Drink)
    Shop_list.append(L)

if N == 1:
    MED = Drink[0]*Drink[1]
    flag = 1
Shop_list.sort()

while stack <= M and flag != 1:
    stack = stack + Shop_list[j][1]
    MED = Shop_list[j][1]*Shop_list[j][0] + MED
    if stack > M:
        loss = stack - M
        MED = MED - loss*Shop_list[j][0]
        break
    j += 1
print(MED)

Submission status: Runtime Error

Solution code:
import copy as cp

N, M = map(int, input().split())
A = list(range(N))
B = list(range(N))
Drink = list(range(2))
Shop_list = list()
L = list()
j = 0

for i in range(N):
    A, B = input().split()
    Drink[0] = int(A)
    Drink[1] = int(B)
    L = cp.deepcopy(Drink)
    Shop_list.append(L)

Shop_list.sort()
stack = 0
MED = 0

while stack <= M:
    stack = stack + Shop_list[j][1]
    MED = Shop_list[j][1]*Shop_list[j][0] + MED
    if stack > M:
        loss = stack - M
        MED = MED - loss*Shop_list[j][0]
        break
    j += 1
print(MED)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
import pandas as pd

n, m = map(int, sys.stdin.readline().rstrip().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
df = pd.DataFrame(lines,
                  columns = ["price", "stock"],
                  dtype = float
                  )
df = df.sort_values(by="price")
price = 0
for i in range(n):
    if m - df.iloc[i]["stock"] > 0:
        price += df.iloc[i]["price"] * df.iloc[i]["stock"]
        m -= df.iloc[i]["stock"]
    else:
        price += df.iloc[i]["price"] * m
        break
print(int(price))

Submission status: Runtime Error

Solution code:
import sys
import os

import numpy as np
import pandas as pd

n, m = map(int, input().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
df = pd.DataFrame(lines,
                  columns = ["price", "stock"],
                  dtype = float
                  )
df = df.sort_values(by="price")
price = 0
for i in range(n):
    if m - df.iloc[i]["stock"] > 0:
        price += df.iloc[i]["price"] * df.iloc[i]["stock"]
        m -= df.iloc[i]["stock"]
    else:
        price += df.iloc[i]["price"] * m
        break
print(int(price))

Submission status: Runtime Error

Solution code:
import sys

import numpy as np
import pandas as pd

n, m = map(int, input().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
df = pd.DataFrame(lines,
                  columns = ["price", "stock"],
                  dtype = float
                  )
df = df.sort_values(by="price")
price = 0
for i in range(n):
    if m - df.iloc[i]["stock"] > 0:
        price += df.iloc[i]["price"] * df.iloc[i]["stock"]
        m -= df.iloc[i]["stock"]
    else:
        price += df.iloc[i]["price"] * m
        break
print(int(price))

Submission status: Runtime Error

Solution code:
import numpy as np
import pandas as pd

n, m = map(int, input().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
df = pd.DataFrame(lines,
                  columns = ["price", "stock"],
                  dtype = float
                  )
df = df.sort_values(by="price")
price = 0
for i in range(n):
    if m - df.iloc[i]["stock"] > 0:
        price += df.iloc[i]["price"] * df.iloc[i]["stock"]
        m -= df.iloc[i]["stock"]
    else:
        price += df.iloc[i]["price"] * m
        break
print(int(price))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int , input().split())))
A = sorted(A)
min_money = 0
if A[0][1] >= M:
    min_money = A[0][0] * M
else:
    i = 0
    num_of_buy = A[0][1]
    min_money = A[0][0] * A[0][1]
    while True:
        if num_of_buy + A[i+1][1] > M:
            min_money += A[i+1][0] * (M - num_of_buy)
            break
        else:
            min_money += A[i+1][0] * A[i+1][1]
            num_of_buy += A[i+1][1]
            i += 1
print(min_money)

Submission status: Runtime Error

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

shop = {AB[i][0]:AB[i][1] for i in range(N)}
total = 0
kosuu = 0
while 1:
  key = min(shop.keys())
  for x in range(shop[key]):
    if kosuu < M:
      total += key
      kosuu += 1
    else:
      print(total)
      exit()
  del shop[key]

Submission status: Runtime Error

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(m):
    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: Runtime Error

Solution code:
# C
n, m = map(int, input().split())
ab = [0, 0] * n
for i in range(n):
    ab[i] = map(int, input().split())
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: Runtime Error

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
        else:
             cost=cost-AB[i][0]*j
 else:
      cost+=AB[i][0]*AB[i][1]
      m+=AB[i][1]
    
print(cost)

Submission status: Runtime Error

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==A[i][1]
 m+=A[i][1]
 cost+=AB[i][0]*AB[i][1]
 break

 elif M-m<A[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break

 cost+=AB[i][0]*AB[i][1]
 m+=A[i][1]
    
print(cost)

Submission status: Runtime Error

Solution code:
f = lambda : [int(a) for a in input()]
N,M = f()
arr = [f() for i in range(N)]

count = 0
money = 0
while count < M:
	min_ = -1
	min_i = -1
	for i in range(len(arr)):
		A,B = arr[i]
		if min_ == -1 or A < min_:
			min_ = A
			min_i = i
	A,B = arr[min_i]
	del arr[min_i]
	if count + B >= M:
		money += A*(M - count)
		count = M
		break
	else:
		money += A*B
		count += B

print(money)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
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)

Submission status: Runtime Error

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

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

ans = 0
sum_drinks = 0 #sum of drinks which Takahashi has bought
for i in range(N):
    nos = PNs[i][1] #number of drinks at i_th shop
    nob = min(M-sum_drinks, nos) #number of drinks which he can buy at the shop
    ans += nob*PNs[i][0] #add money he spent at the shop
    sum_drinks += nob
    if s>=M: break

print(ans)

Submission status: Runtime Error

Solution code:
tmp = input()
N = int(tmp.split()[0])
M = int(tmp.split()[1])
A = []
B = []
for i in range(N):
	tmp = input()
	A[i] = int(tmp.split()[0])
	B[i] = int(tmp.split()[1])

cnt=0
total=0
while cnt < M:
	mini = N
	minv = 999999999999999
	for i in range(N):
		if minv > A[i]:
			minv = A[i]
			mini = i
	cnt += B[mini]
	total += A[mini]*B[mini]
	A[mini] = 999999999999999
total -= minv*(cnt-M)
print(total)

Submission status: Runtime Error

Solution code:
tmp = input()
N = int(tmp.split()[0])
M = int(tmp.split()[1])
A = []
B = []
for i in range(N):
	tmp = input()
	A[i] = int(tmp.split()[0])
	B[i] = int(tmp.split()[1])

minv = 100000000000
cnt=0
total=0
while cnt < M:
	mini = N
	for i in range(N):
		if minv > A[i]:
			minv = A[i]
			mini = i
	cnt += B[mini]
	total = A[mini]*B[mini]
	A[mini] = 1000000000000
total -= minv*(cnt-M)
print(total)

Submission status: Runtime Error

Solution code:
num_drink=0
price=0
a.sort()
for i in a:

    if num_drink+i[1]<m:
        
        num_drink+=i[1]
        price+=i[1]*i[0]

    else:
        price+=(m-num_drink)*i[0]

        break
    
print(price)

Submission status: Runtime Error

Solution code:
(n_store, need) = tuple(map(int(input().split())))
lis = []
for i in range(n_store):
  lis.append(tuple(map(int(input().split()))))

lis.sort()
have = 0
sum = 0
for t in lis:
  (price, stock) = t
  if have + stock >= need:
    sum += price * (need - have)
  else:
    sum += price * stock
print(sum)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
lis = []
for _ in range(N):
  a, b = map(int, input().split)
  for l in range(b):
    lis.append(a)
lis.sort()
total = 0
for i in range(M):
  total = total + lis[i]
print(total)

Submission status: Runtime Error

Solution code:
ans = 0
l = [int(i) for i in input().split()]
d = dict([[int(i) for i in input().split()] for j in range(l[0])])
while True:
    m = min(d.keys())
    l[1] -= d[m]
    ans += m*d[m]
    d.pop(m)
    if l[1]<=0:
        break
print(ans-m*abs(l[1]))

Submission status: Runtime Error

Solution code:
ans = 0
l = [int(i) for i in input().split()]
d = dict([[int(i) for i in input().split()] for j in range(l[0])])
    
while True:
    m = min(d.keys())
    l[1] -= d[m]
    ans += m*d[m]
    d.pop(m)
    if l[1]<0:
        break
print(ans-m*abs(l[1]))

Submission status: Runtime Error

Solution code:
data = line.split(" ")
shoplist = [] #店のデータリスト
for i in range(int(data[0])):
    shop = input()
    shopdata = shop.split(" ")
    shop_int = []
    for j in range(len(shopdata)):
        shop_int.append(int(shopdata[j]))
    shoplist.append(shop_int)

payment = 0 #支払い金額
wantdrink = int(data[1]) #ほしい飲み物の数
pricelist = []  #金額のみのデータリスト
for i in range(len(shoplist)):
    pricelist.append(shoplist[i][0])
while wantdrink > 0 :
    pricemin = min(pricelist[i] for i in range(len(pricelist)))
    min_index = pricelist.index(pricemin)
    restdrink = shoplist[min_index][1]
    if restdrink >= wantdrink:
      while restdrink > 0:
        payment += pricemin
        restdrink -= 1
        wantdrink -= 1
        if wantdrink == 0:
              break
    else:
        payment += restdrink * pricemin
        wantdrink -= restdrink
    del shoplist[min_index]
    del pricelist[min_index]
print(payment)

Submission status: Runtime Error

Solution code:
N,M=list(map(int,input().split(" ")))
l=[]
l=[list(map(int,input().split(" "))) for i in range(n)]
drink=0
price=0
i=0
l.sort(key=lambda x: x[0])
while drink<M:
    pri=l[i][0]
    num=l[i][1]
    i+=1
    drink+=num
    price+=pri*num
if drink>M:
    price-=(drink-m)*pri
print(price)