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: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np


# In[71]:


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


# In[72]:


data = np.array(data)


# In[84]:


sorted_data = data[np.argsort(data[:, 0])]


# In[87]:


ans = 0
for i in range(N):
    if sum(sorted_data[:, 1][:i + 1]) <= M:
        ans += sorted_data[i, 0] * sorted_data[i, 1]
        #print(i, sorted_data[i, 0], sum(sorted_data[:, 1][:i + 1]), ans)
    else:
        ans += sorted_data[i, 0] * (M - sum(sorted_data[:, 1][:i]))
        #print(i, sorted_data[i, 0], (M - sum(sorted_data[:, 1][:i])), ans)
        break

print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np


# In[71]:


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


# In[72]:


data = np.array(data)


# In[84]:


sorted_data = data[np.argsort(data[:, 0])]


# In[86]:


ans = 0
for i in range(N):
    if sum(sorted_data[:, 1][:i + 1]) < M:
        ans += sorted_data[i, 0] * sorted_data[i, 1]
        #print(i, sorted_data[i, 0], sum(sorted_data[:, 1][:i + 1]), ans)
    else:
        ans += sorted_data[i, 0] * (M - sum(sorted_data[:, 1][:i]))
        #print(i, sorted_data[i, 0], (M - sum(sorted_data[:, 1][:i])), ans)
        break

print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
tmp = input()
N = int(tmp.split()[0])
M = int(tmp.split()[1])
A = []
B = []
for i in range(N):
	tmp = input()
	A.append(int(tmp.split()[0]))
	B.append(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] = 9999999999999999
total -= minv*(cnt-M)
print(total)

Submission status: Time Limit Exceeded

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

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

a = []
b = []

for i in  range(n):
    a.append(q[i][0])
    b.append(q[i][1])
b.append(0)

s = 0

for i in range(n):
    if sum(b[:i+1])>m:
        s += a[i]*(m-sum(b[:i]))
        break
    s += a[i]*b[i]
print(s)

Submission status: Time Limit Exceeded

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
a = []
b = []

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

money = 0
count = 0

while count < m:
    minimum = min(a)
    num = a.index(minimum)
    money = money + minimum * b[num]
    count = count + b[num]
    if count > m:
        money = money - minimum * (count - m)
    del (a[num])
    del (b[num])

print(money)

Submission status: Time Limit Exceeded

Solution code:
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
a = []
b = []

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

money = 0
count = 0

while count < m:
    minimum = min(a)
    money = money + minimum

    num = a.index(minimum)
    b[num] = b[num] - 1
    if b[num] == 0:
        del(b[num])
        del(a[num])
    count = count + 1

print(money)

Submission status: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
# coding: utf-8

line = input()
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)
shoplist.sort()
payment = 0
wantdrink = int(data[1])
while wantdrink > 0 :
    restdrink = shoplist[0][1]
    if restdrink >= wantdrink:
        payment += wantdrink * shoplist[0][0]
        break
    else:
        payment += restdrink * shoplist[0][0]
        wantdrink -= restdrink
        del shoplist[0]
print(payment)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

line = input()
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)
shoplist = sorted(shoplist)
payment = 0 #支払い金額
wantdrink = int(data[1]) #ほしい飲み物の数
while wantdrink > 0 :
    restdrink = shoplist[0][1]
    if restdrink >= wantdrink:
        payment += wantdrink * shoplist[0][0]
        break
    else:
        payment += restdrink * shoplist[0][0]
        wantdrink -= restdrink
        del shoplist[0]
print(payment)

Submission status: Time Limit Exceeded

Solution code:
a = 0
l = [int(i) for i in input().split()]
s = [[int(i) for i in input().split()] for j in range(l[0])]
sp = [s[j][0] for j in range(l[0])]
sv = [s[j][1] for j in range(l[0])]
while True:
    m = sp.index(min(sp))
    if (l[1]-sv[m])>0:
        l[1] -= sv[m]
        a += sp[m]*sv[m]
        sp.pop(m)
        sv.pop(m)
    else:
        a += sp[m]*l[1]
        break
print(a)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

line = input()
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: Time Limit Exceeded

Solution code:
line = input()
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)
    restwater = shoplist[min_index][1]
    while restwater > 0:
        payment += pricemin
        restwater -= 1
        wantdrink -= 1
        if wantdrink == 0:
            break
    del shoplist[min_index]
    del pricelist[min_index]
print(payment)

Submission status: Time Limit Exceeded

Solution code:
line = input()
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]) #ほしい飲み物の数
while wantdrink > 0 :
    pricelist = []  #金額のみのデータリスト
    for i in range(len(shoplist)):
        pricelist.append(shoplist[i][0])
    pricemin = min(pricelist[i] for i in range(len(pricelist)))
    min_index = pricelist.index(pricemin)
    restwater = shoplist[min_index][1]
    while restwater > 0:
        payment += pricemin
        restwater -= 1
        wantdrink -= 1
        if wantdrink == 0:
            break
    del shoplist[min_index]
print(payment)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
AB = []
ans = 0
for i in range(N):
    A,B = map(int,input().split())
    t = A,B
    AB.append(t)    
AB.sort()
l = []
for i in range(len(AB)):
    for x in range(AB[i][1]):
        l.append(AB[i][0])
i = 0
while M > 0:
    ans += l[i]
    M -= 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(AB)):
    if M < 0:
        break
    for x in range(AB[i][1]):
        if M > 0:
            ans += AB[i][0]
            M -= 1
       
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(len(AB)):
    for x in range(AB[i][1]):
        if M > 0:
            ans += AB[i][0]
            M -= 1
        

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M=map(int,input().split())
A=[]

for i in range(N):
    A+=[[i for i in map(int,input().split())]]
A=np.array(A)
A=A[A[:,0].argsort(),:]


count=0
price=0
for i in range(N):
    if A[0,1]>=M-count:
        price+=A[0,0]*(M-count)
        break
    else:
        price+=A[0,0]*A[0,1]
        count+=A[0,1]
    A=np.delete(A,0,0)
    
print(price)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(N):
    A1=[i for i in map(int,input().split())]
    if i==0:
        A+=[A1]
    else:
        for j in range(len(A)):
            if A[j][0]>A1[0]:
                A.insert(j,A1)
                break
            elif j==i-1:
                A+=[A1]

count=0
price=0
for i in range(N):
    if A[0][1]>=M-count:
        price+=A[0][0]*(M-count)
        break
    else:
        price+=A[0][0]*A[0][1]
        count+=A[0][1]
    A.pop(0)
    
print(price)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(N):
    A1=[i for i in map(int,input().split())]
    if i==0:
        A+=[A1]
    else:
        for j in range(len(A)):
            if A[j][0]>A1[0]:
                A.insert(j,A1)
                break
            elif j==i-1:
                A+=[A1]

count=0
price=0
while count<M:
    if A[0][1]>=M-count:
        price+=A[0][0]*(M-count)
        break
    else:
        price+=A[0][0]*A[0][1]
        count+=A[0][1]
    A.pop(0)
    
print(price)

Submission status: Time Limit Exceeded

Solution code:
#Energy Drink Collector
N, M = map(int, input().strip().split())
A = []
B = []
for n in range(N):
	a, b = map(int, input().strip().split())
	A.append(a)
	B.append(b)
total   = 0
collect = 0
while True:
	min_i = A.index(min(A))
	if collect + B[min_i] < M:
		total += A[min_i]*B[min_i]
		collect += B[min_i]
		del A[min_i]
		del B[min_i]
	else:
		total += A[min_i]*(M - collect)
		collect = M
		break
print(total)

Submission status: Time Limit Exceeded

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

AB = []

for i in range(N) : 
    tmp_AB = [int(i) for i in input().split()]
    AB.append(tmp_AB)
    
P_list = []

for i in range(N) : 
    for j in range(AB[i][1]) : 
        P_list.append(AB[i][0])

P_list_sorted = sorted(P_list)

sum = 0

for i in range(M) : 
    sum += P_list_sorted[i]
    
print(sum)

Submission status: Time Limit Exceeded

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


for _ in range(N):
    drink.append(list(map(int, input().split())))
    drink = sorted(drink)

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

print(cost)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
drink = []
cost = 0
count = 0
d_count = 0
rest = 0


for _ in range(N):
    drink.append(list(map(int, input().split())))
    drink = sorted(drink)

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

print(cost)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
drink = []
cost = 0
count = 0
d_count = 0
rest = 0


for _ in range(N):
    drink.append(list(map(int, input().split())))
    drink = sorted(drink)

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

Submission status: Time Limit Exceeded

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

a=[]
b=[]
cnt=0
sum=0


for i in range(0,n):
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)


while m>0:
    mindex = a.index(min(a))
    num = m if m<b[mindex] else b[mindex]
    sum+=a[mindex]*num
    m-=num
    del b[mindex]
    del a[mindex]



print(sum)

Submission status: Time Limit Exceeded

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

a=[]
b=[]
cnt=0
sum=0

for i in range(0,n):
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)


while m>0:
    mindex = a.index(min(a))
    sum+=a[mindex]*b[mindex]
    m-=b[mindex]
    sa = a[mindex]
    del b[mindex]
    del a[mindex]

while m<0:
    m+=1
    sum-=sa

print(sum)

Submission status: Time Limit Exceeded

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

a=[]
b=[]
cnt=0
sum=0

for i in range(0,n):
    ta,tb = map(int,input().split())
    a.append(ta)
    b.append(tb)


while m>0:
    mindex = a.index(min(a))
    for i in range(0,b[mindex]):
        sum+=a[mindex]
        m-=1
        if m<=0:
            break
    del b[mindex]
    del a[mindex]

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M = list(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())))
for i in range(1, len(a)):
    j = i - 1
    ele1 = a[i]
    ele2 = b[i]
    while a[j] > ele1 and j >= 0:
        a[j+1] = a[j]
        b[j+1] = b[j]
        j -= 1
    a[j+1] = ele1
    b[j+1] = ele2
money=0
for i in range(N):
    money+=a[i]*b[i]
    M-=b[i]
    if M <= 0:
        break
if M == 0:
    print(money)
else:
    print(money + (a[i] * M))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(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())))

change = True
while change:
    change = False
    for i in range(N-1):
        if a[i] > a[i+1]:
            a[i], a[i+1] = a[i+1], a[i]
            b[i], b[i+1] = b[i+1], b[i]
            change = True

money=0
for i in range(N):
    money+=a[i]*b[i]
    M-=b[i]
    if M <= 0:
        break
if M == 0:
    print(money)
else:
    print(money + (a[i] * M))

Submission status: Time Limit Exceeded

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

ab.sort()

AB=[[ab[i][0]]*ab[i][1] for i in range(n)]
A=[]
for i in AB:
    A+=i
ans=0

for i in range(m):
    ans+=A[i]
print(ans)

Submission status: Time Limit Exceeded

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

ab.sort()

AB=[[ab[i][0]]*ab[i][1] for i in range(n)]
ans=0
cnt=0
for i in AB:
    for z in i:
        ans+=z
        cnt+=1
        if cnt>=m:
            print(ans)
            exit()

Submission status: Time Limit Exceeded

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

ABlist = [list(map(int,input().split())) for n in range(N)]
Alist = [ab[0] for ab in ABlist]
Blist = [ab[1] for ab in ABlist]

sum = 0
flg = False
while True:
    min_ = min(Alist)
    min_index = Alist.index(min_)
    b_num = Blist[min_index]
    for i in range(b_num):
        M -= 1
        sum += min_
        if M==0:
            flg = True
            break
    Blist.remove(b_num)
    Alist.remove(Alist[min_index])
    if flg == True:
        break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
count = yen = 0
li = [list(map(int,input().split())) for i in range(N)]
li.sort() 
for i in range(0,len(li),1):
  count += li[i][1] 
  yen += li[i][0]*li[i][1] 
  if count > M: 
    for j in range(0,li[i][1],1):
      count -= 1
      yen -= li[i][0]
      if count == M: 
        break
print(yen)

Submission status: Time Limit Exceeded

Solution code:
import sys

def parse(inp):
    n,m=map(int,next(inp).split())
    shop=[list(map(int,next(inp).split())) for _ in range(n)]
    
    return n,m,shop
  
def main(inp):
    n,m,shop=inp
    maxint=9223372036854775807
    
    if(n==1): return shop[0][0]*m
        
    dp=[[maxint for _ in range(m+1)] for _ in range(2)]
    
    for i in range(min(shop[0][1]+1,m+1)):
        dp[0][i]=shop[0][0]*i    
    
    for i in range(1,n):
        for j in range(m+1):
            for k in range(1,shop[i][1]+1):
                if(j-k>=0):
                    dp[1][j] = min(dp[0][j],dp[0][j-k]+shop[i][0]*k)
                else:
                    dp[1][j] = min(dp[0][j],dp[1][j])
        
        if(i==n-1): break
        for j in range(m+1):
            dp[0][j]=dp[1][j]
    
    return dp[1][m]
  
print(main(parse(sys.stdin)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())
x = np.array([list(map(int, input().split())) for i in range(N)])
minprice = min(x[0:,0])
number = np.argmin(x[0:,0])
price = 0
while True:
    if M <= x[number][1]:
        price += int(minprice * M)
        break
    else:
        price += minprice * x[number][1]
        M -= x[number][1]
        x = np.delete(x, number, 0)
        minprice = min(x[0:,0])
        number = np.argmin(x[0:,0])
print(price)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split(" "))
list = []
for i in range(N):
    A,B = map(int,input().split(" "))
    list.append([A,B])
#print(list)
list = sorted(list)
#print(list)
cost = 0
while True:
    #print(cost)
    M -= list[0][1]
    if M <= 0:
        cost += list[0][0] * (list[0][1]+M)
        break
    else:
        cost += list[0][0] * list[0][1]
        list.remove(list[0])
print(cost)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split(' '))
cost = 0
count = 0

mlist = list()
for i in range(n):
  mlist.append(list(map(int,input().split(' '))))
mlist.sort(key=lambda x: x[0])
#  print(mlist)


for i in range(n):
  ablist = mlist[i]
#  print(ablist)
  for j in range(ablist[1]):
    count += 1
    if count <= m:
      cost += ablist[0]
#      print(count,"本", cost,"円")
print(cost)

Submission status: Time Limit Exceeded

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

sum=0
count=0
a=[];b=[]
for i in range(n):
    atmp,btmp=map(int,input().split())
    a.append(atmp); b.append(btmp)


while(m!=0):
    mina=min(a)
    for i in range(n):
            if a[i]==mina:
                if m>b[i]:
                    sum+=a[i]*b[i]
                    m-=b[i]
                    b[i]=0
                else:
                    sum+=m*a[i]
                    m=0
            if b[i]==0:
                a[i]=float('inf')

print(sum)

Submission status: Time Limit Exceeded

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

require = M
price = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    a = A.pop(minidx)
    b = B.pop(minidx)
    if(require >= b):
#        print("buy = {}, price = {}".format(b, a))
        price = price + a * b
        require = require - b
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + a * require
        require = 0

print(price)

Submission status: Time Limit Exceeded

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

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

B.sort()

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=B[0][0]
    for i in B:#どの店で買うか
        if Min>=i[0]:
            Min=i[0]
            l=k
        k+=1

    for x in range(B[l][1]):#何個かえるか

        m+=1
        if M==X+m:#max
            money+=m*Min
            print(money)
            break


    money+=m*Min
    X+=m

    B.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数

Submission status: Time Limit Exceeded

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

C=[input().split() for i in range(N)]

k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=int(C[0][0])
    for i in C:#どの店で買うか
        if Min>=int(i[0]):
            Min=int(i[0])
            l=k
        k+=1

    for x in range(int(C[l][1])):#何個かえるか

        m+=1
        if M==X+m:#max
            money+=m*Min
            print(money)
            break


    money+=m*Min
    X+=m

    C.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数

Submission status: Time Limit Exceeded

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

C=[input().split() for i in range(N)]

CX=[]
for i in C:
    for j in i:
        try:CX.append(int(j))

        except ValueError:
            pass

CA=[]
CB=[]
i=0

for k in CX:

    if (i+2)%2==0:
        CA.append(CX[i])
    else:
        CB.append(CX[i])
    i+=1



k=0
l=0#何番目の店
m=0#その店で買う数
money=0
X=0#持ち数

while M>X:
    Min=int(C[0][0])
    for i in C:#どの店で買うか
        if Min>=int(i[0]):
            Min=int(i[0])
            l=k
        k+=1
    
    for x in range(int(C[l][1])):#何個かえるか

        m+=1
        if M==X+m:#max
            money+=m*Min
            print(money)
            break


    money+=m*Min
    X+=m

    C.pop(l)#取り出す
    #リセット
    k=0
    l=0
    m=0#その店で買う数

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
for i in range(M):
    if M-k>A[0][1]:
        sumcost += A[0][0]*A[0][1]
        k += A[0][1]
        A.pop(0)
    else:
        sumcost += A[0][0]*(M-k)
        break

print(sumcost)

Submission status: Time Limit Exceeded

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

print(sumcost)

Submission status: Time Limit Exceeded

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

print(sumcost)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = map(int, input().split())
    D = [tuple(map(int, input().split())) for _ in range(N)]
    D.sort()
    ans = 0
    while M > 0:
        a, b = D.pop(0)
        ans += a * min(M, b)
        M -= min(M, b)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()
price_howmany = {}
price_list = []

for _ in range(N):
    tmp = read_int()
    if tmp[0] not in price_list:
        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()

def solve():
    price = 0
    global M
    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: Time Limit Exceeded

Solution code:
import sys

stdin = sys.stdin

read_int = lambda : list(map(int,stdin.readline().split()))

N,M = read_int()

price_howmany = {}
price_list = []
for i in range(N):
    tmp = read_int()
    if tmp[0] not in price_list:
        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()

def solve():
    price = 0
    global M
    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: Time Limit Exceeded

Solution code:
import numpy as np

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

for i in range(0, N):
    a, b = np.array(list(map(float, input().split())))
    A.append(a)
    B.append(b)

cnt = 0
sum = 0
flag = 0
inf = float('inf')
arrayA = np.array(A)
arrayB = np.array(B)
for j in range(0, N):
    idx = A.index(min(arrayA))
    pay = arrayA[idx]
    num = arrayB[idx]
    arrayA[idx]=inf
    if cnt + num < M :
        cnt += num
        sum += pay*num
    else :
        diff = int(M - cnt)
        for t in range(0, diff):
            sum += pay
            cnt += 1
            if cnt == M :
                flag = 1
                print(int(sum))
                break
    if flag == 1:
        break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int,input().split())
A_s = []
for _ in range(N):
  A_s.append(list(map(int,input().split())))
## Aiの順にsortする
A_s = sorted(A_s,key=lambda x:x[0])
## そこまでの合計本数を足したlistを作成？
A_s = np.array(A_s)
nums = []
[nums.append(np.sum(A_s[:k+1,1:])) for k in range(len(A_s))]
#print("num",nums)
## あとは要件を満たす場所を見つけて、そこまではただ掛け算をして、それ以降は足す
## for文をbreakで抜けてもいいか〜〜
#print(nums)
money = 0
pre_num = 0
for a_s,num in zip(A_s,nums):
  if num <= M:
    money += a_s[1] * a_s[0]
    pre_num = num
  else:
    money += (M-pre_num) * a_s[0]
    break
  #print(money)
print(money)

Submission status: Time Limit Exceeded

Solution code:
[n,m] = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    [ai,bi] = [int(i) for i in input().split()]
    if ai in dic.keys():
        dic[ai] += bi
    else:
        dic[ai] = bi
sum = 0
ls = sorted(list(dic.keys()))
while m > 0:
    for i in range(len(ls)):
    #print(dic)
        if dic[ls[i]] >= m:
            sum += min(dic.keys()) * m
            m = 0
            break
        else:
            sum += dic[min(dic.keys())]*min(dic.keys())
            m -= dic.pop(min(dic.keys()))
print(sum)

Submission status: Time Limit Exceeded

Solution code:
tmp = [int(i) for i in raw_input().split()]
N = tmp[0]
M = tmp[1]
sum = 0
buy = 0

alllist1 = []
alllist2 = []

for i in range(N):
    tmp2 = [int(i) for i in raw_input().split()]
    alllist1.extend([tmp2[0]])
    alllist2.extend([tmp2[1]])


for i in range(M):
    if M > 0:
        minmoney = min(alllist1)
        banme = alllist1.index(minmoney)
        kazu = alllist2[banme]
        M = M - kazu

        if M < 0:
            M = M + kazu
            sum += (minmoney*M)
            M = 0
        else:
            sum += minmoney*kazu
            alllist1.remove(minmoney)
            alllist2.remove(kazu)

    elif M == 0:
        break

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import scipy as sp

total_cost = 0

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

AB_list = sp.array([0,0])
for i in range(N):
    AB_list = sp.vstack([AB_list, sp.array(list(map(int, input().split())))])


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

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

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
shop=dict()
for x in range(N):
    shop[x]=[int(x) for x in input().split()]

min=1
count=0
used_money=0;
while True:
    for x in range(len(shop)):
        if shop[x][0] == min and shop[x][1]!=0:
            for n in range(shop[x][1]):
                if(count<M):
                    shop[x][1]-=1
                    count+=1
                    used_money+=shop[x][0]
                else:
                    break
    if count==M:
        break       
    min+=1
    
print(used_money)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
dic ={}
for i in range(N):
  A,B =map(int,input().split())
  if A in dic.keys():
      dic[A] = dic[A] + B
  else:
      dic[A] = B
a = sorted(dic)
res = 0
b = 0
flag = False
for i,s in enumerate(a):
  #print(i)
  if b > M or b== M:
    res = res - (b-M)*a[i-1]
    flag = True
    break
  res += s*dic[s]
  #print(res,s)
  b += dic[s]
  #print(b)
if flag:
    print(res)
else:
    res = res - (b-M)*a[i]
    print(res)

Submission status: Time Limit Exceeded

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

for i in range(n):
    a.append(al[i][0])
    b.append(al[i][1])

ans = 0
while(m > 0):
    if m > b[a.index(min(a))]:
        m -= b[a.index(min(a))]
        ans += a[a.index(min(a))]*b[a.index(min(a))]
        b.pop(a.index(min(a)))
        a.pop(a.index(min(a)))
    else :
        ans += a[a.index(min(a))]*m
        break
print(ans)