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:
N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
A = []
B = []
for i in range(N):
	A.append(L[i][0])
	B.append(L[i][1])
cost = 0
num = 0
while True:
	if num == M:
		break
	cost = cost + min(A)*min(B[A.index(min(A))], M - num)
	num = num + min(B[A.index(min(A))], M - num)
	B.pop(A.index(min(A)))
	A.remove(min(A))
print(cost)
exit()

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(_) for _ in input().split())
ab_list = [[int(i) for i in input().split()] for i in range(n)]
a_list = []
b_list = []
for i in range(n):
    a_list.append(ab_list[i][0])
    b_list.append(ab_list[i][1])


buy = 0
money = 0
while (n >= 0):
    min_a = min(a_list)
    min_index = a_list.index(min_a)
    if (buy + b_list[min_index] < m):
        money += b_list[min_index] * a_list[min_index]
        buy += b_list[min_index]
    else:
        money += (m - buy) * a_list[min_index]
        break

    a_list.pop(min_index)
    b_list.pop(min_index)

    n -= 1

print(money)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
a = []
b = []
ans = 0

for i in range(N):
    store = input().split()
    a.append(int(store[0]))
    b.append(int(store[1]))

nokori = M
max_ = max(a)
for i in range(M):
    if nokori >= 1:
        index = a.index(min(a))
        if b[index] != 0 and nokori - (b[index]) >= 0:
            ans += a[index] * b[index]
            nokori -= b[index]
            a[index] = max_ + 1
            b[index] = 0
        else:
            ans += a[index] * nokori
            break
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

price_howmany = dict(price_howmany)

def solve():
    price = 0
    many = 0
    global price_howmany
    global M
    while M > 0:
        low_price = min(price_howmany.keys())
        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: Time Limit Exceeded

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

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

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

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(1):
    mina=min(a)
    for i in range(n):
            if a[i]==mina:
                if m-count>b[i]:
                    sum+=a[i]*b[i]
                    count+=b[i]
                    b[i]=0
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
            if b[i]==0:
                a[i]=float('inf')
            if count==m:
                print(sum)
                break

    if count==m:
        break

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
  aa, bb = map(int,input().split())
  a.append(aa)
  b.append(bb)
ans = 0
mini = 10000000000
while(1):
  for i in range(n):
    if a[i] < mini:
      mini = a[i]
      index = i
  ans = ans + a[index]*min(m,b[index])
  m = m - min(m,b[index])
  if m == 0:
    break
  a.pop(index)
  b.pop(index)
  n = n - 1
  mini = 10000000000
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = map(int, input().split())
money = []
for i in range(n):
  a, b = map(int, input().split())
  money += [a] * b

money.sort()
print(np.sum(money[0:m]))

Submission status: Time Limit Exceeded

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

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

sum = 0
ans = 0
for i in range(N):
	idx = A.index(min(A))
	
	if(sum+B[idx] >= M):
		for i in range(B[idx]):
			ans += A[idx]
			sum += 1
			if(sum >= M):
				break
		break
	ans += A[idx]*B[idx]
	sum += B[idx]
	A[idx] = 10000000
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)]
cnt = 0
yen = 0

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

for i in range(N):
    for j in range(int(AB[i][1])):
        cnt += 1
        yen += AB[i][0]
        if cnt == M:
            print(yen)
            break

Submission status: Time Limit Exceeded

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

a = []
b = []

for i in range(n):
    in1,in2 = map(int,input().split())
    a.append(in1)
    b.append(in2)

a = np.array(a)
b = np.array(b)

ans = 0
num = m
for i in range(n):
    min_index = np.argmin(a)
    ans += a[min_index] * b[min_index]
    num -= b[min_index]
    if num < 0:
        ans += a[min_index] * num
        break

    a[min_index] = 10000000000


print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

n, m = map(int, input().split())

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]

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

ans = 0
need = copy.deepcopy(m)

for i in range(m):
    minprice = a.index(min(a))
    if b[minprice] >= need:
#        print('a')
        ans += a[minprice] * need
#        print(ans)
        break
    
    else:
#        print('b')
        ans += a[minprice] * b[minprice]
        need -= b[minprice]
        del a[minprice]
        del b[minprice]

#    print(ans)

        
    

print(ans)

Submission status: Time Limit Exceeded

Solution code:
b=list(map(int,input().split()))
L=[]
l=[]
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort(key=lambda x: x[0])
L=[LL[i][0] for i in range(b[0])]
l=[LL[i][1] for i in range(b[0])]
x=0
z=0
y=b[1]
while y>=0 and not L==[]:
    if L==[]:
        print(x-y*(-1)*w)
        z=1
        break
    else:
        y-=l[0]
        x+=l[0]*L[0]
        z=l[0]*L[0]
        w=L[0]
        l=l[1:]
        L=L[1:]
print(x-y*(-1)*w)

Submission status: Time Limit Exceeded

Solution code:
def insertion_sort(a, n):
    for i in range(1, n):
        v = a[i]
        j = i - 1
        while ((j >=0) & (a[j] > v)):
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
    return a

store_num, drink_num = [int(i) for i in input().split(" ")]
a_list = []
for i in range(store_num):
    a, b = [int(i) for i in input().split(" ")]
    for j in range(b):
        a_list.append(a)
b_list = insertion_sort(a_list, len(a_list))
ans = 0
for i_ in range(drink_num):
    ans += b_list[i_]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(' '))
A = []
B = []
for n in range(N):
  A_n, B_n = map(int, input().split(' '))
  A.append(A_n)
  B.append(B_n)
  
# calc answer
drink = 0
ans = 0
while(drink < M):
  min_i = A.index(min(A))
  if B[min_i] > 0:
    B[min_i] -= 1
    drink += 1
    ans += A[min_i]
  else:
    del A[min_i]
    del B[min_i]
  
print(ans)

Submission status: Time Limit Exceeded

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

def bubble_sort(lst):
    for i in reversed(range(len(lst))):
        for j in range(i):
            if lst[j][0] > lst[j + 1][0]:
                lst[j], lst[j + 1] = lst[j + 1], lst[j]

bubble_sort(a)
purchase_price = 0

for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)

Submission status: Time Limit Exceeded

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
    del A[min_Ai]
    del B[min_Ai]

Submission status: Time Limit Exceeded

Solution code:
x = input()
y = x.split(" ")
parameters = [int(i) for i in y]
N = parameters[0]
M = parameters[1]
i = N
count = 0
A = [[0] * M for i in range(N)]
while(i > 0):
    x = input()
    y = x.split(" ")
    A[count] = [int(i) for i in y]
    count += 1
    i -= 1

cash = 0
while(M > 0):
    i = 0
    min = A[i][0]
    index = 0
    while(i < N):
        if(min > A[i][0]):
            min = A[i][0]
            index = i
        i += 1
    if(M - A[index][1] >= 0):
        M -= A[index][1]
        cash += A[index][1] * A[index][0]
    else:
        cash += A[index][0] * M
        M -= A[index][1]
    del A[index]
    N -= 1

print(cash)

Submission status: Time Limit Exceeded

Solution code:
N, M =  map(int, (input().split(' ')))
A_list = []
B_list = []
money = 0
while len(A_list) < N:
    A, B =  map(int, (input().split(' ')))
    A_list.append(A)
    B_list.append(B)

while True:
    i = A_list.index(min(A_list))
    if B_list[i] < M:
        money += A_list[i] * B_list[i]
        M -= B_list[i]
    else:
        money += A_list[i] * M
        M = 0 
    A_list[i] = 99999999999999999999999999999999999999
    if M == 0:
        print(money)
        exit()

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
price = []
honsu = []
for i in range(n):
  a,b = map(int,input().split())
  price.append(a)
  honsu.append(b)
for j in range(n):
  k = j + 1
  while(k<n):
    if price[j] > price[k]:
      temp1 = price[j]
      temp2 = honsu[j]
      price[j] = price[k]
      honsu[j] = honsu[k]
      price[k] = temp1
      honsu[k] = temp2
    k+=1
money = 0
for l in range(n):
  if(m-honsu[l]>0):
    m -= honsu[l]
    money += honsu[l] * price[l]
  else:
    c = abs(m-honsu[l])
    m -= honsu[l]-c
    money += (honsu[l]-c) * price[l]
  if(m == 0):
    break;
print(money)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A = np.array(A)
B = A[:,1]
A = A[:,0]

#print(N)
#print(M)
#print(A)
#print(B)
x = 0
cost = 0

while x < M:
    i = np.argmin(A)
    
    if x + B[i] <= M:
        cost += A[i] * B[i]
        x += B[i]
        A = np.delete(A, i)
        B= np.delete(B, i)
        #print(A)
        #print(B)
#        print(cost)
#        print(x)
    else:
        #print(A[i])
        #print(M-x)
        cost += A[i] * (M-x)
        x += (M-x)
        #print(cost)
        #print(x)


print(cost)

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

bought = 0
price = 0
while(M > bought):
#    print("bought = {}, price = {}".format(bought, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    if(M - bought >= B[minidx]):
#        print("buy = {}, price = {}".format(B[minidx], A[minidx]))
        price = price + A[minidx] * B[minidx]
        bought = bought + B[minidx]
    elif(M - bought < B[minidx]):
#        print("buy = {}, price = {}".format(M - bought, A[minidx]))
        price = price + A[minidx] * (M - bought)
        bought = M
    del A[minidx]
    del B[minidx]

print(price)

Submission status: Time Limit Exceeded

Solution code:
n,m=list(map(int,input().split(" ")))
al=[0 for i in range(n)]
bl=[0 for i in range(n)]
for i in range(n):
    al[i],bl[i]=list(map(int,input().split(" ")))
    have=0
yen=0
while have<m:
    k=al.index(min(al))
    pri=al.pop(k)
    num=bl.pop(k)
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)

Submission status: Time Limit Exceeded

Solution code:
def main():
	N, M = map(int, input().split())
	A = []
	B = []
	for i in range(N):
		a, b = map(int, input().split())
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		minp = min(A)
		for i in range(N):
			if A[i] == minp:
				mc = B[i]
				A[i] = 10**10
				break
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += minp
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += minp * mc
	return

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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

print(sum(sorted(drinks)[:m]))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
a = []
b = []
ans = 0

for i in range(N):
    store = input().split()
    a.append(int(store[0]))
    b.append(int(store[1]))

nokori = M
for i in range(M):
    if nokori >= 1:
        index = a.index(min(a))
        if nokori - (b[index]) >= 0:
            ans += a[index] * b[index]
            nokori -= b[index]
            a.pop(index)
            b.pop(index)
        else:
            ans += a[index] * nokori
            break
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
while ki <= m:
    ind = prise.index(min(prise))
    for p in range(conte[ind]):
        cost += min(prise)
        ki += 1
        if ki >= m:
            break
    prise.pop(ind)
    conte.pop(ind)
    if prise == []:
        break
    if ki == m:
        break
print(cost)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n,m=map(int,input().split())
lst=[]
for i in range(n):
    a=list(map(int,input().split()))
    x=bisect.bisect_left(lst,a)
    lst.insert(x,a)
ans=0
num=0
for i in lst:
    if i[1]+num>=m:
        ans+=i[0]*(m-num)
        break
    ans+=i[0]*i[1]
    num+=i[1]
print(ans)

Submission status: Time Limit Exceeded

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+[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=sum+A[i][0]*A[i][1]
  else:
    sum=sum+count*A[i][0]
    break
print(sum)

Submission status: Time Limit Exceeded

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

a = []
b = []

for i in range(n):
    in1,in2 = map(int,input().split())
    a.append(in1)
    b.append(in2)

a = np.array(a)
b = np.array(b)

ans = 0
num = m
for i in range(n):
    min_index = np.argmin(a)

    if num - b[min_index] > 0:
        ans += a[min_index] * b[min_index]
        num -= b[min_index]
    else:
        ans += a[min_index] * num
        break

    a[min_index] = 1000000000000


print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = input()
y = x.split(" ")
parameters = [int(i) for i in y]
N = parameters[0]
M = parameters[1]
i = N
count = 0
A = [[0] * M for i in range(N)]
while(i > 0):
    x = input()
    y = x.split(" ")
    A[count] = [int(i) for i in y]
    count += 1
    i -= 1

cash = 0
while(M > 0):
    i = 0
    min = 1000000001
    index = 0
    while(i < N):
        if(min > A[i][0]):
            min = A[i][0]
            index = i
        i += 1
    if(M - A[index][1] >= 0):
        M -= A[index][1]
        cash += A[index][1] * A[index][0]
    else:
        cash += A[index][0] * M
        M -= A[index][1]
    del A[index]
    N -= 1

print(cash)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = input().split()
N = int(n[0])
M = int(n[1])


num_list = []
pr_list = []

for i in range(N):
    a = input().split()
    
    num_list.append(int(a[1]))
    pr_list.append(int(a[0]))

x = np.argsort(np.array(pr_list))

tmp = 0
for i in range(100000):
    key = np.array(num_list)[x[i]]
    if M - key > 0:
        tmp += int(pr_list[x[i]])*key
        M -= key
    elif M - key < 0:
        tmp += int(pr_list[x[i]])*M
        break
    else:
        if i == 0:
            tmp = int(pr_list[x[i]])*M
            break
        else:
            break

print(str(tmp))

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()
while M-k > A[0][1]:
    sumcost += A[0][0]*A[0][1]
    k += A[0][1]
    A.pop(0)
sumcost += A[0][0]*(M-k)

print(sumcost)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
c={}
d=[]
for i in range(n):
  a,b=map(int,input().split())
  if a not in c:
    c[a]=0
  c[a]+=b
  if a not in d:
    d.append(a)
  
d.sort()

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

Submission status: Time Limit Exceeded

Solution code:
b=list(map(int,input().split()))
L=[]
l=[]
for i in range(b[0]):
    q=list(map(int,input().split()))           
    L.append(q[0])
    l.append(q[1])
x=0
z=0
y=b[1]    
while y>=0 and not L==[]:
    if L==[]:
        print(x-y*(-1)*w)
        z=1
        break
    else:
        a=L.index(min(L))
        y-=l[a]
        x+=l[a]*L[a]
        z=l[a]*L[a]
        w=L[a]
        l=l[:a]+l[a+1:]
        L=L[:a]+L[a+1:]
print(x-y*(-1)*w)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int, input().split())
AB=[]
for i in range(N):
  AB.append(list(map(int,input().split())))
AB.sort()
count=0
summary=0
for i in range(N):
  for j in range(AB[i][1]):
    summary+=AB[i][0]
    count+=1
    if count==M:
      print(summary)
      break

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    A.append(x1)
    B.append(y1)
    
yen = 0
num = 0
while num < M:
    a  = min(A)
    ind = A.index(a)
    
    if num + B[ind] <= M:
        yen += a * B[ind]
        num += B[ind]
        del A[ind]
        del B[ind]
    else:
        yen += a * (M - num)
        break
print(yen)

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(1):
    mina=min(a)
    for i in range(n):
        if a[i]==mina:
            sum+=a[i]
            count+=1
            b[i]-=1
        if b[i]==0:
            a[i]=float('inf')
        if count==m:
            print(sum)
            break
    if count==m:
        break

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split(" "))
A=["" for i in range(N)]
B=["" for i in range(N)]
for i in range(N):
    A[i],B[i] = map(int, input().split(" "))
total_num=0
total_mon=0
while True:
    min_a = min(A)
    ind = A.index(min_a)
    add = B[ind]
    total_num+=add
    if total_num>=M:
        add = add - (total_num-M)
        total_mon+=add*min_a
        break
    total_mon+=add*min_a
    A.pop(ind)
    B.pop(ind)
print(total_mon)

Submission status: Time Limit Exceeded

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

money = 0
count = 0
while count < M:
    min_ = 1000000000
    index = 0
    for i in range(len(A_B)):
        if A_B[i][0] < min_:
            min_ = A_B[i][0]
            index = i
    if count+A_B[index][1] <= M:
        count += A_B[index][1]
        money += A_B[index][0] * A_B[index][1]
    else:
        money += A_B[index][0] * (M-count)
        count = M
    A_B.pop(index)
print(money)

Submission status: Time Limit Exceeded

Solution code:
def main():
	N, M = map(int, input().split())
	A = []
	B = []
	for i in range(N):
		a, b = map(int, input().split())
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		minp = min(A)
		for i in range(N):
			if A[i] == minp:
				mc = B[i]
				A[i] = 10**10
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += minp
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += minp * mc
	return

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())
#n = ip()                                     #入力整数1つ
n,m= (int(i) for i in input().split())       #入力整数横2つ以上
#b = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a = []
b = []
for i in range(n):
    c,d = (int(i) for i in input().split())
    a.append(c)
    b.append(d)
s = 0
sp = 0
while m>s:
    minpos = a.index(min(set(a)))
    if s+b[minpos]>=m:
        amo = m-s
  #      print(amo)
        s+=amo
        sp+=(a[minpos]*amo)
 #       print(s,sp)
 #       print(a,b)
    else:
        s+=b[minpos]
        sp+=(a[minpos]*b[minpos])
        a.pop(minpos)
        b.pop(minpos)
#        print(s,sp)
 #       print(a,b)
print(sp)

Submission status: Time Limit Exceeded

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

print(sum(sorted(money)[0:m]))

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()
while k < M:
    if A[0][1] >= M-k:
        sumcost += A[0][0]*(M-k)
        break
    else:
        sumcost += A[0][0]*A[0][1]
        k += A[0][1]
        A.pop(0)



print(sumcost)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = input().split()
N = int(n[0])
M = int(n[1])


num_list = []
pr_list = []

for i in range(N):
    a = input().split()
    
    num_list.append(int(a[1]))
    pr_list.append(int(a[0]))

x = np.argsort(np.array(pr_list))

tmp = 0
for i in range(1000):
    if M - np.array(num_list)[x[i]] > 0:
        tmp += int(pr_list[x[i]])*np.array(num_list)[x[i]]
        M -= np.array(num_list)[x[i]]
    elif M - np.array(num_list)[x[i]] < 0:
        tmp += int(pr_list[x[i]])*M
        break
    else:
        if i == 0:
            tmp = int(pr_list[x[i]])*M
            break
        else:
            break

print(str(tmp))

Submission status: Time Limit Exceeded

Solution code:
N, M =  map(int, (input().split(' ')))
A_list = []
B_list = []
money = 0
while len(A_list) < N:
    A, B =  map(int, (input().split(' ')))
    A_list.append(A)
    B_list.append(B)

while True:
    i = A_list.index(min(A_list))
    if B_list[i] < M:
        money += A_list[i] * B_list[i]
        M -= B_list[i]
    else:
        money += A_list[i] * M
        M = 0 
    A_list.pop(i)
    B_list.pop(i)
    if M == 0:
        print(money)
        exit()

Submission status: Time Limit Exceeded

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

a = []
b = []
c = []

for i in range(n):
    in1,in2 = map(int,input().split())
    a.append(in1)
    b.append(in2)

a = np.array(a)
b = np.array(b)

d = a

ans = 0
num = m
for i in range(n):
    min_index = np.argmin(a)

    if num - b[min_index] < 0:
        ans += a[min_index] * num
        break
    else:
        ans += a[min_index] * b[min_index]
        num -= b[min_index]

    a[min_index] = 1000000000000


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = list(map(int,input().split()))
d = []
for i in range(N[0]):
    A = list(map(int,input().split()))
    for j in range(A[1]):
        d.append(A[0])
d.sort()
s = 0
for i in range(N[1]):
    s+=d[i]
print(s)

Submission status: Time Limit Exceeded

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

l = []
for n in range(0, N):
    a, b = map(int, input().split())
    l += [a] * b

ls = sorted(l)
by = ls[0:M]
print (sum(by))

Submission status: Time Limit Exceeded

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

count = 0
while True:
    select = 0
    min_val = AB_array[0][0]
    for i in range(1,len(AB_array)):
        if AB_array[i][0] < min_val:
            min_val = AB_array[i][0]
            select = i
    if M <= AB_array[select][1]:
        count += AB_array[select][0] * M
        break
    else:
        M -= AB_array[select][1]
        count += AB_array[select][0] * AB_array[select][1]
        AB_array.pop(select)

print(count)

Submission status: Time Limit Exceeded

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

count = 0
money = 0
while count < m:
    count += b[a.index(min(a))]
    if count <= m:
        money += a[a.index(min(a))] * b[a.index(min(a))]
    else:
        money += a[a.index(min(a))] * (m - count + b[a.index(min(a))])

    del b[a.index(min(a))]
    del a[a.index(min(a))]
    
print(money)

Submission status: Time Limit Exceeded

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

a_order = a.copy()
a_order.sort()

c = m + 0
ans = 0

while c > 0 :
    a_index_now = a.index(a_order[0]) + 0
    b_now = b[a_index_now] + 0
    if c >= b_now :
        ans += a_order[0] * b_now
        c -= b_now
        a.pop(a_index_now)
        b.pop(a_index_now)
        a_order.pop(0)
    else :
        ans += a_order[0] * c
        c = 0

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
	N, M = map(int, input().split())
	A = []
	B = []
	for i in range(N):
		a, b = map(int, input().split())
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		mp = min(A)
		for i in range(N):
			if A[i] == mp:
				mc = B[i]
				A[i] = 10**10
		for i in range(mc):
			M -= 1
			cost += mp
			if M <= 0:
				print(cost)
				return
	return

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

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
for i in range(M):
    money += AB[np.argmin(AB[:, 0]), 0]
    AB[np.argmin(AB[:, 0]), 1] -= 1
    if AB[np.argmin(AB[:, 0]), 1] == 0:
        AB[np.argmin(AB[:, 0]), 0] = 10e6
print(money)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = map(int, input().split())
money = []
for i in range(n):
  a, b = map(int, input().split())
  money += [a] * b

money = sorted(money)
print(sum(money[0:m]))

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(x) for x in input().split())
A=[]
B=[]
for i in range(N):
    a,b = (int(x) for x in input().split())
    A.append(a)
    B.append(b)
ans = 0

while M > 0:
    ind = A.index(min(A))
    b = B.pop(ind)

    if M < b:
        b = M
        M = 0
    else:
        M -= b

    ans += A.pop(ind) * b
    
print(ans)

Submission status: Time Limit Exceeded

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

money = 0
items = 0
for i in range(N):
    if (items + AB[i][1] < M):
        money += AB[i][0] * AB[i][1]
        items += AB[i][1]
    else:
        for j in range(1,AB[i][1]+1):
            if (items+j == M):
                money += AB[i][0] * j
                items +=j

print(money)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
x = []
y = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
ans = 0

while(1):
    if m == 0:
        break
    mintmp = min(x)
    tmp = x.index(mintmp)
    if y[tmp] <= m:
        ans += mintmp*y[tmp]
        m -= y[tmp]
        x.pop(tmp)
        y.pop(tmp)
    else:
        ans += mintmp*m
        m = 0
print(ans)

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()
while k < M:
    sumcost += A[0][0]
    A[0][1] -= 1
    if A[0][1]<1:
        A.pop(0)
    k += 1



print(sumcost)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n, m = map(int, input().split())

ans=[]
def targetAdd(a):
    bisect.insort_left(ans, a)

for i in range(n):
    a, b = map(int, input().split())
    for j in range(b):
        targetAdd(a)

print(sum(ans[:m]))

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())

categories = [ tuple(li()) for _ in range(N) ]
categories.sort()

total = 0
def buy_M(cate, M, cost):
    if M <= 0:
        return cost
    if cate[0][1] >= M:
        cur_cost = cate[0][0] * M
        return cur_cost + cost
    else:
        rest = M - cate[0][1]
        cur_cost = cate[0][1] * cate[0][0]
        return buy_M(cate[1:], rest, cost + cur_cost)
print(buy_M(categories, M, 0))