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:
#C
N, M = [int(_) for _ in input().split()]

value = 0
limit = 0
num_box = {}
for i in range(N):
    A, B = [int(_) for _ in input().split()]
    num_box[A] = B

num_box = sorted(num_box.items())
counter = 0
ans = 0
key_num = 0

for j in range(M):
    limiter = num_box[key_num][1]#上限は1番目
    ans = ans + num_box[key_num][0]#金額は0番目
    counter += 1
    if counter == limiter:
        key_num += 1
        counter = 0
    
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# -*- conding: utf-8 -*-
import numpy as np

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

min_value_index_list = np.argsort(A)

cnt = 0
for i in range(len(min_value_index_list)):
    if cnt+B[min_value_index_list[i]] < M:
        result = A[min_value_index_list[i]] * B[min_value_index_list[i]]
        cnt += B[min_value_index_list[i]]
    elif cnt+B[min_value_index_list[i]] > M:
        result = A[min_value_index_list[i]] * M
print(result)

Submission status: Runtime Error

Solution code:
from operator import itemgetter

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

a = []
R=[]
D = 0
X = 0
for i in range(N):
    a.append(list(map(int,input().split())))
if N ==1:
    Z = M*a[0]
    print(Z)
else:
    a.sort(key = itemgetter(0))

    for i in range(N):
        D += a[i][1]
        if D>M:
            R.append(i)
            break
    for i in range(R[0]+1):
        X += a[i][0]*a[i][1]
    Y = X-(D-M)*a[R[0]][0]
    print(Y)

Submission status: Runtime Error

Solution code:
import scipy as sp

total_cost = 0

N, M = (map(int, input().split()))
A = sp.array(list(map(int, input().split())))
B = sp.array(list(map(int, input().split())))

AB_list = sp.stack([A, B]).T

AB = AB_list[:, AB_list[0,:].argsort()]

A_list = AB[0,:]
B_list = AB[1,:]
for i in range(N):
    if B_list[i]<M:
        M -= B_list[i]
        total_cost += A_list[i] * B_list[i]
    else:
        total_cost += M * A_list[i]
print(total_cost)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 21:40:34 2019

@author: iwata
"""

N,M = map(int, input().split())
numlist =[]
money = 0
count = 0
count1 = 0
count2 = 0

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

numlist.sort()

while count <= M:
    while numlist[count1][1] <= count2:
        money = money + numlist[count1][0]
        count = count + 1
        count2 = count2 + 1
        if count == M:
            break
    count1 = count1 + 1
    count2 = 0
    
print(money)

Submission status: Runtime Error

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

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

# print(N,M)
S = sorted(T)
# print(S)

s = 0
ss =[]
for it in range(N):
    s = s + S[it][1]
    ss.append(s)
    # print(it,s)
    if s > M:
        idx = it
        break
#
# print(idx)
# print("s",s)

ans = 0

if N == 1:
    print(S[0][0]*S[0][1])
elif M == 1:
	print(S[0][1]*1)
else:
    for it in range(idx+1):
        # print(ss[it])
        if it == idx:
            ans += S[it][0]*(M-ss[it-1])
        else:
            ans += S[it][0]*S[it][1]
        # print("ans",ans)
    print(ans)

Submission status: Runtime Error

Solution code:
n,m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(n)]
e.sort()
#print(n,m,e)
#e=dict(e)
#print(n,m,e,e[0][0]*m)

total=0
if m <= e[0][1]:
  total=e[0][0]*m
else:
  tmp=e[0][0]*e[0][1]
  m-=e[0][1]


#print(m)  
flag=0
for i in range(1,n):
  if 0 <= m <e[i][1] and flag==0:
    flag=1
    total=tmp+e[i][0]*m
  tmp+=e[i][0]*e[i][1]
  m-=e[i][1]

print(total)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N,M = list(map(int,input().split()))
# price_howmany = defaultdict(int)
price_howmany = {}
price_list = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    price_list.append(tmp[0])
    if tmp[0] in price_howmany:
        price_howmany[tmp[0]] += tmp[1]
    else:
        price_howmany[tmp[0]] = tmp[1]
# price_list.sort(reverse=True)
price_list.sort()

# price_howmany = dict(price_howmany)

def solve():
    price = 0
    many = 0
    global M
    # while M > 0:
        # low_price = min(price_howmany.keys())
        # low_price = price_list.pop()
        # many = min(M,price_howmany.pop(low_price))
        # price += many * low_price
        # M -= many
    for low_price in price_list:
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
n,m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(n)]
e.sort()
#print(n,m,e)
#e=dict(e)
#print(n,m,e,e[0][0]*m)

total=0
if m < e[0][1]:
  total=e[0][0]*m
else:
  tmp=e[0][0]*e[0][1]
  m-=e[0][1]


#print(m)  
flag=0
for i in range(1,n):
  if 0 <= m <e[i][1] and flag==0:
    flag=1
    total=tmp+e[i][0]*m
  tmp+=e[i][0]*e[i][1]
  m-=e[i][1]

if n==1:
  total=e[0][0]*e[0][1]


print(total)

Submission status: Runtime Error

Solution code:
import itertools

n,m = map(int, input().split())
AB = []
ans = 0
for n in range(n):
    a,b = map(int,input().split())
    AB.append([a,b])
AB.sort()
A,B = zip(*AB)
A,B = list(A), list(B)

i = list(_ for _ in itertools.accumulate(B) if _ <= m)

B = B[:len(i)] + [m-i[-1]]
A = A[:len(B)]

ans = sum([a*b for a,b in zip(A,B)])
print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
dic ={}
for i in range(N):
  A,B =map(int,input().split())
  dic[A] = B
a = sorted(dic)
res = 0
b = 0
i = 0
while i < N:
  if b>M or b==M:
    break
  res = res + a[i]*dic[a[i]]
  b += dic[a[i]]
  i+=1
res = res-(b-M)*a[(i-1)]
print(res)

Submission status: Runtime Error

Solution code:
N,M=(int(x) for x in input().split())
A=[0]*N
B=[0]*N
for i in range(N):
    A[i],B[i]=(int(x) for x in input().split())
K=0
T=0
Q=sorted(A)
for i in range(N):
    s=A.index(Q[i])
    if M-T<B[s]:
        K+=(M-T)*Q[i]
        break
    else:
        K+=B[s]*Q[i]
        T+=B[s]
    Q.pop(i)
    B.pop(s)
    if T==M:
        break
print(K)

Submission status: Runtime Error

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

cnt = 0
ans = 0
while cnt < M:
    min_cost = min(A)
    amount = B[A.index(min_cost)]
    if cnt + amount <= M:
        ans += min_cost * amount
        cnt += amount
    else:
        ans += min_cost * (M - cnt)
        break
    A = [e for e in A if e != min_cost]
    B = [e for e in B if e != amount]
    
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N,M = list(map(int,input().split()))
price_howmany = defaultdict(int)
price_list = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    price_howmany[tmp[0]] += tmp[1]
    price_list.append(tmp[0])
# price_list.sort(reverse=True)
price_list.sort()

price_howmany = dict(price_howmany)

def solve():
    price = 0
    many = 0
    global M
    # while M > 0:
        # low_price = min(price_howmany.keys())
        # low_price = price_list.pop()
        # many = min(M,price_howmany.pop(low_price))
        # price += many * low_price
        # M -= many
    for low_price in price_list:
        many = many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
        if M == 0: break
    print(price)

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	temp1, temp2 = map(int, input().split())
	#temp1 = 1
	#temp2 = 1
	l1.append(temp1)
	l2.append(temp2)

while True:
	min_index = l1.index(min(l1))
	if rest >= l2[min_index]:
		ans += (min(l1) * l2[min_index])
		rest -= l2[min_index]
	else:
		ans += (min(l1) * rest)
		break
	l1.pop(min_index)

print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	temp1, temp2 = map(int, input().split())
	#temp1 = 1
	#temp2 = 1
	l1.append(temp1)
	l2.append(temp2)

while True:
	min_index = l1.index(min(l1))
	if(rest >= l2[min_index]):
		ans += (min(l1) * l2[min_index])
		rest -= l2[min_index]
	else :
		ans += (min(l1) * rest)
		break
	l1.pop(min_index)

print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	temp1, temp2 = map(int, input().split())
	#temp1 = 1
	#temp2 = 1
	l1.append(temp1)
	l2.append(temp2)

while True:
	min_index = l1.index(min(l1))
	if(rest >= l2[min_index])
		ans += (min(l1) * l2[min_index])
		rest -= l2[min_index]
	else :
		ans += (min(l1) * rest)
		break
	l1.pop(min_index)

print(ans)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import numpy

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

D = 0
X = 0
for i in range(N):
    a.append(list(map(int,input().split())))
a.sort(key = itemgetter(0))

for i in range(N):
    D += a[i][1]
    if D>M:
        for k in range(i+1):
            X += a[k][0]*a[k][1]
            Y = X-(D-M)*a[i][0]
        break
print(Y)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N,M = list(map(int,input().split()))
price_howmany = defaultdict(int)
price_list = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    price_howmany[tmp[0]] += tmp[1]
    price_list.append(tmp[0])
price_list.sort(reverse=True)

price_howmany = dict(price_howmany)

def solve():
    price = 0
    many = 0
    global M
    while M > 0:
        # low_price = min(price_howmany.keys())
        low_price = price_list.pop()
        many = min(M,price_howmany.pop(low_price))
        price += many * low_price
        M -= many
    print(price)

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

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

dict = {}
for i in range(0,n):
    dict[a[i]] = b[i]

l = sorted(a)

for j in range(0,n-1):
    if l[j] == l[j-1]:
        dic[l[j]] = dic[l[j]]+dic[l[j-1]]
        l[j-1] = -j
        dic[l[j-1]] = 0

#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
if __name__ == "__main__":
    NM = list(map(int, input().split()))
    n = NM[0]
    m = NM[1]
    mydict = {}
    for i in range(n):
        money_can = list(map(int, input().split()))
        money = money_can[0]
        can = money_can[1]
        if(money not in mydict.keys()):
            mydict[money] = []
        mydict[money].append(can)
    buynow = 0
    moneynow = 0

    mydict = OrderedDict(sorted(mydict.items()))
    for i in mydict.keys():
        if(buynow >= m):
            break
        for canNO in mydcit[i]:
            if(buynow >= m):
                break
            if(can + buynow <= m):
                moneynow += can*i
                buynow += can
            else:
                need = m - buynow
                moneynow += need*i
                buynow += need
        else:
            continue
    print(moneynow)

Submission status: Runtime Error

Solution code:
 N, M = map(int, input().split(" "))
A_list = []
B_list = []
total = 0

for i in range(N):
    A, B = map(int, input().split(" "))
    A_list.append(A)
    B_list.append(B)

z = list(zip(A_list, B_list))
z.sort()

for a, b in z:
    if b > M:
        total += M * a
        break
    else:
        total += b * a
        M -= b

print(total)

Submission status: Runtime Error

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

dict = {}
for i in range(0,n):
    dict[a[i]] = b[i]

l = sorted(a)

for j in range(0,n-1):
    if l[j] == l[j-1]:
        dic[l[j]] = dic[l[j]]+dic[l[j-1]]
        dic[l[j-1]] = 0
        l[j-1] = -j

#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)

Submission status: Runtime Error

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

for N in range(n):
    a[N] = list(map(int,input().split()))
b=sorted(a)
print(b)
c=0
f=0
while c<m:
    f=f+int(b[0][0])
    c=c+1
    if c+1>int(b[0][1]):
        b[0][1]=int(b[0][1])+int(b[1][1])
        del b[0]
print(f)

Submission status: Runtime Error

Solution code:
import sys
N,M = map(int,input().split())
A = []
B = []
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    A.append(tmp_a)
    B.append(tmp_b)
sum_A,sum_B = 0,0
for i in range(N):
    if (M-sum_B) >= B[A.index(min(A))]:
        sum_A += min(A)*B[A.index(min(A))]
        sum_B += B[A.index(min(A))]
        A.pop(A.index(min(A)))
        B.pop(A.index(min(A)))
    else:
        sum_A += min(A)*(M-sum_B)
        print(sum_A)
        sys.exit()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	temp1, temp2 = map(int, input().split())
	#l1[i],l2[i]  = map(int, input().split())
	l1.append(temp1)
	l2.append(temp2)

while true:
	min_index = l1.index(min(l1))
	ans += (min(l1) * l2[min_index])
	rest -= l2[min_index]
	if rest <= 0:
		break
	l1.pop(min_index)

print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
N,M = list(map(int,input().split()))
price_howmany = defaultdict(int)
price_list = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    price_howmany[tmp[0]] += tmp[1]
    price_list.append(tmp[0])
price_list.sort(reverse=True)

price_howmany = dict(price_howmany)

def solve():
    price = 0
    many = 0
    global M
    while M > 0:
        # low_price = min(price_howmany.keys())
        low_price = price_list.pop()
        many = min(M,price_howmany[low_price])
        price += many * low_price
        M -= many
        price_howmany.pop(low_price)
    print(price)

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
#N = 1
#M = 1
l1 = []
l2 = []
ans = 0
rest = M
for i in range(N):
	l1[i],l2[i]  = map(int, input().split())
	#l1[0],l2[0] = 3,1

while true:
	min_index = l1.index(min(l1))
	ans += (min(l1) * l2[min_index])
	rest -= l2[min_index]
	if rest <= 0:
		break
	l1.pop(min_index)

print(ans)

Submission status: Runtime Error

Solution code:
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M <= 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Submission status: Runtime Error

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

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

money = 0
num = 0
for A,B in sorted(AB.items()):
  if num+B < M:
    money += A*B
  	num += B
  else:
    money += A*(M-num)
    break
  
print(money)

Submission status: Runtime Error

Solution code:
def main():
	N, M = map(int, input().split())
	S = {}
	for i in range(N):
		a, b = map(int, input().split())
		S[a] = b
	sorted_price_list = sorted(S)
	cost = 0
	for i in range(N):
		a = sorted_price_list[i]
		mc = S[a]
		if mc < M:
			M -= mc
			cost += a * mc
		else:
			cost += a * M
			print(cost)
			return
	return

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M < 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
import numpy

N, M = map(int,input().split())
a = []
R=[]
D = 0
X = 0
for i in range(N):
    a.append(list(map(int,input().split())))
a.sort(key = itemgetter(0))

for i in range(N):
    D += a[i][1]
    if D>M:
        R.append(i)
        break
for i in range(R[0]+1):
    X += a[i][0]*a[i][1]
Y = X-(D-M)*a[R[0]][0]
print(Y)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
d = dict([list(map(int, input().split()))[::-1] for i in range(N)])
d = sorted(d.items(), key=lambda x: x[1])
c = p = i = 0

while c < M:
    if c + d[i][0] <= M:
        c += d[i][0]
        p += d[i][1] * d[i][0]
        i += 1
    else:
        p += d[i][1] * (M - c)
        print(c)
        break

print(p)

Submission status: Runtime Error

Solution code:
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m:
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
        if m <= 0:
            break
print(ans)

Submission status: Runtime Error

Solution code:
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
print(AB)
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M < 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split()) 
a = []
for i in range(n):
	a.append(map(int, input().split())
s = 0
while m>0  :
	min = 0
	temp = 0
	for i in range(n):
		if(a[0][i]>min):
			min = a[0][i]
			temp = i
	while a[1][temp]>0:
		s += a[0][temp]
		a[1][temp] -=1
		m -= 1
print (s)

Submission status: Runtime Error

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

dict = {}
for i in range(0,n):
    dict[a[i]] = b[i]
    
for j in range(0,n-1):
    l = sorted(a)
    if l[j] == l[j-1]:
        dic[l[j]] = dic[l[j]]+dic[l[j-1]]
        dic[l[j-1]] = 0
        l[j-1] = -j

#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
l={}
nedan=[]
ans=0
num=0
small=0
for i in range(n):
    kane,kazu=map(int,input().split())
    if kane in nedan:
        l[kane]+=kazu
    else:
        l[kane]=kane
    nedan.append(kane)
nedan.sort()
set(nedan)
while True:
    if num+l[nedan[small]]<m:
        ans+=nedan[small]*l[nedan[small]]
        num+=l[nedan[small]]
        small+=1
    else:
        ans+=(m-num)*nedan[small]
        break
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N, M = map(int, raw_input().split())

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count
    if count == M: break

print(yen)

Submission status: Runtime Error

Solution code:
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        print(ans)
        exit
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]

Submission status: Runtime Error

Solution code:
def main():
	N, M = map(int, input().split())
	S = {}
	for i in range(N):
		a, b = map(int, input().split())
		S[a] = b
	sorted_price_list = sorted(S)
	cost = 0
	for i in range(N):
		a = sorted_price_list[i]
		mc = S[a]
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += a
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += a * mc
	return

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
l1 = []
l2 = []
ans = 0
rest = M
for i in N+1:
	l1[i],l2[i]  = map(int, input().split())

while true:
	min_index = l1.index(min(l1))
	ans += min(l1) * l2[min_index]
	rest -= l2[min_index]
	if rest == 0:
		break
	l1.pop(min_index)

print(ans)

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
dic ={}
for i in range(N):
  A,B =map(int,input().split())
  dic[A] = B
a = sorted(dic)
res = 0
b = 0
i = 0
while i < N:
  if b>M:
    break
  res = res + a[i]*dic[a[i]]
  b += dic[a[i]]
  i+=1
res = res-(b-M)*a[(i-1)]
print(res)

Submission status: Runtime Error

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

dct_a_tmp = {}
dct_b = {}
for n in range(N):
  a,b = map(int, input().split())
  dct_a_tmp[n] = a
  dct_b[n] = b

# 安い順にkeyをソート
list_a = sorted(dct_a_tmp.items(), key=lambda x: x[1])


# 安い順に買っていく
'''
1.不足本数を計算
2.不足本数と購入できる本数を比較する
a.全部購入していいようなら通常購入
b.ダメなら、購入していい本数だけ購入
'''
cnt_buied = 0
cost = 0
inf = 10 ** 18


for i in range(inf):
  want_buy = M - cnt_buied 
  
  if dct_b[list_a[i][0]] <= want_buy:
    cost += list_a[i][1] * dct_b[list_a[i][0]]
    cnt_buied += dct_b[list_a[i][0]] 
  else:
    cost += list_a[i][1] * want_buy
    
  if cnt_buied >= M:
    break

print(cost)

Submission status: Runtime Error

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

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

ans = 0
count = 0
while(count < M):
  min_A = min(A)
  min_Ai = A.index(min_A)
  B_min = B[min_Ai]
  if count + B_min >= M:
    print(ans + min_A * (M - count))
    break
  else:
    ans += min_A * B_min
    count += B_min
    A.remove(min_A)
    B.remove(min_A)

Submission status: Runtime Error

Solution code:
N, M = map(float, input().split())
dict = {}
for i in range(N):
	A, B = map(flost, input().split())
	dict[A] = B
dict_sorted = sorted(dict.items())
sum = 0
ans = 0
for i in dict_sorted:
	k = i[0]
	v = i[1]
	ans = k * v + ans
	sum = sum + v
	if sum > M:
		break
a = sum - M
ans = ans - a*k
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
from operator import itemgetter
N,M=(int(x) for x in input().split())
A=[]

for i in range(N):
  D=[int(x) for x in input().split()]
  A=A.append([D])    
result=A.sort(key=itemgetter(0))
count=M
sum=0
for i in range(N):
  if count-A[i][1]>0:
    count=count-A[i][1]
    sum+=A[i][0]*A[i][1]
  else:
    sum+=count*A[i][0]
    break
print(sum)

Submission status: Runtime Error

Solution code:
n, m = map(int,(input().split()))
d = {}
for i in range(n):
    a, b = map(int,(input().split()))
    d[a]=b
d = sorted(d.items())
ans = 0
for i in range(n):
    if d[i][1] >= m: # 残り本数 >= この値段の本数
        ans += d[i][0]*m
        break
    else:
        ans += d[i][0]*d[i][1]
        m -= d[i][1]
print(ans)

Submission status: Runtime Error

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

sortAB = sorted(AB)

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

print(ans)

Submission status: Runtime Error

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

A = [x[0] for x in a]
A_sorted = sorted(A)
ans = 0
nokori = M
for c in A_sorted:
	for j in range(N):
		if c == A[j]:
			ans += A[j]*min(a[1][j],nokori)
			nokori -= min(a[1][j],nokori)
		if nokori <= 0:
			print(ans)
			exit()

Submission status: Runtime Error

Solution code:
4 30
6 18
2 5
3 10
7 9

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n,m=map(int,input().split())
a=np.zeros(n)
b=np.zeros(n)
for i in range(n):
    a[i],b[i]=map(int,input().split())
x=np.argsort(a)
ans=0
i=0
while m>0:
    ans+=a[x[i]]*min(b[x[i]],m)
    i+=1
    m-=b[x[i]]
print(round(ans))

Submission status: Runtime Error

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

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

sum = 0
ans = 0
for i in range(N):
	idx = num_list.index(min(A))
	sum += A[idx]*B[idx]
	A[idx] = 10000000
	ans += 1
	if(sum >= M):
		break

print(ans)

Submission status: Runtime Error

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

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

# print(N,M)
S = sorted(T)
# print(S)

s = 0
ss =[]
for it in range(N):
    s = s + S[it][1]
    ss.append(s)
    # print(it,s)
    if s > M:
        idx = it
        break
#
# print(idx)
# print("s",s)

ans = 0

if N == 1:
    print(T[0][0]*T[0][1])
else:
    for it in range(it+1):
        # print(ss[it])
        if it == idx:
            ans += S[it][0]*(M-ss[it-1])
        else:
            ans += S[it][0]*S[it][1]
        # print("ans",ans)
    print(ans)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
N = a[0]
M = a[1]
dct = {}
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] in dct:
        val = dct[temp[0]] + temp[1]
        dct[temp[0]] = val
    else:
        dct[temp[0]] = temp[1]

dct = sorted(dct.items())
ruiseki = 0
loop = 0

cost = []
nums = []
ans = 0
for i in range(N):
    cost.append(dct[i][0])
    nums.append(dct[i][1])
if nums[0] >= M:
    print(str(cost[0]*M))
else:
    ans += cost[0]*nums[0]
    for i in range(1, 100001):
        nums[i] += nums[i-1]
        if nums[i] >= M:
            print(str(ans + cost[i]*(M - nums[i-1])))
            break
        ans += cost[i]*(nums[i]-nums[i-1])

Submission status: Runtime Error

Solution code:
import numpy as np

n,m = list(map(int,input().split()))
a = []
b = []
stc = {}
# stc = np.zeros([n,2])

for i in range(n):
  ta, tb = list(map(int,input().split()))
  stc[tb] = ta
  b.append(tb) 

bud = 0
nb = sorted(b)

# nb = stc[stc[:,1].argsort(),:]
while m > 0:
  if m  > = nb[i]:
    bud += nb[i]*stc[nb[i]]
    m -= nb[i]
  else:
    bud += stc[nb[i]]*m
    m = 0

print(bud)

Submission status: Runtime Error

Solution code:
import numpy as np
n, m = map(int, input().split())

v = np.zeros((n, m))
a = np.zeros((n,2))


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


aSorted = sorted(a, key=lambda ai: ai[0])

mc = 0
ans = 0
for ai, bi in aSorted:
    if mc + bi <= m:
        mc += bi
        ans += bi * ai
    else:
        mm = m - mc
        ans += mm * ai
        break
print(int(ans))

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

count = 0
money = 0
while True:
    count += ab[0][1]
    if count <= m:
        money += ab[0][0] * ab[0][1]
        del ab[0]
    else:
        money += ab[0][0] * (m - count + ab[0][1])
        break

print(money)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
test = dict(zip(a,b))
test = sorted(test.items())
# print(test)
# test_item = test.values()
# test_key = test.keys()
# print(test_item)
# print(test_key)
# for i in range(n):
#     if m-test[i][1] >=0:

i=0
while m>0:
    if m-test[i][1] >=0:
        ans += test[i][0]*test[i][1]
        m -=test[i][1]
    else:
        ans += test[i][0]*m
        m=0
        print(ans)
        exit()
    i+=1
print(ans)

Submission status: Runtime Error

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

c = p = i = 0

while c < M:
    if c + d[i][1] <= M:
        c += d[i][1]
        p += d[i][0] * d[i][1]
        i += 1
    else:
        p += d[i][0] * (M - c)
        break

print(p)

Submission status: Runtime Error

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

for i in range(1,n+1):
    a, b = map(int,input().split())
    dict[a] = b

l = list(dict.keys())
l.sort()

#print(l)
#print(dict)

ex = 0
num = 0

for i in range(0,n):
    #print(l[i])
    if num + dict[l[i]] <= m:
        ex = ex + l[i] * dict[l[i]]
        num = num + dict[l[i]]
    else:
        ex = ex + l[i] * (m - num)
        num = m
    #print([ex,num])
    if num == m:
        break

print(ex)