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:
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
c = []
for i in range(n):
    a, b = map(int, input().split())
    c += [a]*min(b,m)
c.sort()
print(sum(c[:m]))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
inf = 10 ** 10
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:
    cost, index = min(a), a.index(min(a))
    if b[index] < m - cnt:
        cnt += b[index]
        ans += cost * b[index]
        a[index] = inf
    else:
        ans += cost * (m - cnt)
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
li = list(map(int,input().split()))
num = li[0]
want = li[1]
cost = []
max_num = []
total_num = 0
total_cost = 0
for i in range(num):
	a = list(map(int,input().split()))
	cost.append(a[0])
	max_num.append(a[1])
while want > total_num:
	min_cost = min(cost)
	m = cost.index(min_cost)
	if total_num + max_num[m] > want:
		total_cost += (want - total_num) * cost[m]
		total_num = want
	else:
		total_cost += max_num[m] * cost[m]
		total_num += max_num[m]
		cost.remove(cost[m])
		max_num.remove(max_num[m])
print(total_cost)

Submission status: Time Limit Exceeded

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

A = []
#B = []
for i in range(N):
#    print(i)
#    a, b = map(int, input().split())
    A.append(list(map(int, input().split())))
#    B.append(b)
    
    A.sort(key=lambda x: x[0])

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = list(map(int,input().split()))
a = []
b = []
dic = {}
count = 0
"""
for i in range(n):
    x,y = list(map(int,input().split()))
    dic[x] = y
dic = sorted(dic.items())



for key in dic:
    if m - dic[key] > 0:
        count += key * dic[key]
        m = m - dic[key]
    else:
        count += m * key
        break
print(count)
"""
            



for i in range(n):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
count = 0


while m > 0:
    mi = min(a)
    d = a.index(mi)
    if m - b[d] > 0 : # Bi本買う
        m = m-b[d]
        count += b[d] * mi
    else:
        count += m * mi
        break
    del a[d]
    del b[d]
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,m = list(map(int,input().split()))
a = []
b = []
dic = {}
count = 0
"""
for i in range(n):
    x,y = list(map(int,input().split()))
    dic[x] = y
dic = sorted(dic.items())



for key in dic:
    if m - dic[key] > 0:
        count += key * dic[key]
        m = m - dic[key]
    else:
        count += m * key
        break
print(count)
"""
            



for i in range(n):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
count = 0


while m > 0:
    mi = min(a)
    if m - b[a.index(mi)] > 0 : # Bi本買う
        m = m-b[a.index(mi)]
        count += b[a.index(mi)] * min(a)
    else:
        count += m * mi
        break
    d = a.index(mi)
    del a[d]
    del b[d]
print(count)

Submission status: Time Limit Exceeded

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

while m > 0:
    if m - b[a.index(min(a))] > 0 : # Bi本買う
        m = m-b[a.index(min(a))]
        count += b[a.index(min(a))] * min(a)
    else:
        count += m * min(a)
        break
    d = a.index(min(a))
    del a[d]
    del b[d]

print(count)

Submission status: Time Limit Exceeded

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

while True:

    if m - b[a.index(min(a))] > 0 : # Bi本買う
        m = m-b[a.index(min(a))]
        count += b[a.index(min(a))] * min(a)
    else:
        count += m * min(a)
        break
    d = a.index(min(a))
    del a[d]
    del b[d]

print(count)

Submission status: Time Limit Exceeded

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

while True:
    mi = min(a)

    if m - b[a.index(min(a))] > 0 : # Bi本買う
        m = m-b[a.index(min(a))]
        count += b[a.index(min(a))] * min(a)
        
    elif m - b[a.index(min(a))] == 0:
        count += m * min(a)
        
        break
    else:
        count += m * min(a)
        break
    d = a.index(min(a))
    del a[d]
    del b[d]

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
money = 0
while M > 0:
  AB_mn = min(AB)
  Ai, Bi = AB_mn[0], AB_mn[1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB_mn)
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]=list(map(int,input().split()))

mi=0
bou=0
ans=0
sup=0
while bou<m:
    mi=a.index(min(a))
    bou+=b[mi]
    ans+=a[mi]*b[mi]
    sup=a[mi]
    a[mi]=max(a)

ans-=(bou-m)*sup
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def key_func(n):
    return n[0]

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

money = 0

while m > 0:
    ind = a_b.index(min(a_b,key=key_func))
    i = min(m,a_b[ind][1])
    money = money + a_b[ind][0]*i
    m = m - i
    del a_b[ind]

print(money)

Submission status: Time Limit Exceeded

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

sort_a = sorted(set(a))
money = 0

for ai in sort_a:
    ind = [i for i, x in enumerate(a) if x == ai]
    for i in ind:
        x = min(m,b[i])
        m = m - x
        money = money + a[i]*x
    if m <= 0:
        break

print(money)

Submission status: Time Limit Exceeded

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

ans = 0
m = 0
while m < M:
    a, b = ab.pop(0)
    tm = min([b, M - m])
    ans += tm * a
    m += tm
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect

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

price_list = []
stock_list = []
for i in range(N):
    A, B = map(int, input().split())
    index = bisect.bisect_left(price_list, A)
    price_list.insert(index, A)
    stock_list.insert(index, B)

ans = 0
rest = M
for i in range(N):
    if stock_list[i] < rest:
        ans += price_list[i] * stock_list[i]
        rest -= stock_list[i]
    else:
        ans += rest * price_list[i]
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
x = [[int(j) for j in input().split()] for i in range(n)]
a = []
b = []
for i in range(n):
  a.append(x[i][0])
  b.append(x[i][1])
mon = 0
cnt = 0
ind = 100000
while(cnt < m):
  min = 10000000000
  for i in range(n):
    if a[i] < min:
      min = a[i]
      ind = i
  while(b[ind] > 0 and cnt != m):
    cnt += 1
    mon += a[ind]
    b[ind] -= 1
  a[ind] = 100000000000
print(mon)

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

ans = 0
while m > 0:
    mina = min(a)
    idx = a.index(mina)
    bn = b[idx]
    if m < bn:
        ans += mina * m
        m = 0
    else:
        ans += mina * bn
        m -= bn
    a.pop(idx)
    b.pop(idx)

print(ans)

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)

ans = 0
while m > 0:
    idx = A.index(min(A))
    p = A.pop(idx)
    a = B.pop(idx)
    if a >= m:
        ans += p * m
        m -= a
    else:
        ans += p * a
        m -= a
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    input_list = list(map(int, input().split()))
    N = input_list[0]
    M = input_list[1]

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

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

    for i in range(N):
        if i == 0:
            prices = [A[0]]*B[0]
        else:
            prices.extend([A[i]]*B[i])

    sorted_prices = sorted(prices)

    answer = 0

    for i in range(M):
        answer += sorted_prices[i]

    print(answer)

Submission status: Time Limit Exceeded

Solution code:
n, m=map(int, input().split())
x=0
a=[]
b=[]
for _ in range(n):
	s, t=map(int, input().split())
	a.append(s)
	b.append(t)
while m>0:
	p=a.index(min(a))
	x+=(a[p]*min(b[p],m))
	m-=b[p]
	del a[p]
	del b[p]
print(x)

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
e=[]
for i in range(a):
    c,d=map(int, input().split())
    e+=[c]*d
e.sort()
print(sum(e[:b]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M=map(int,input().split())
A=np.zeros(N,dtype=int)
B=np.zeros(N,dtype=int)
for n in range(N):
    A[n],B[n]=map(int,input().split())
orderA=np.argsort(A)
oAs=A[orderA]*B[orderA]
oB=B[orderA]
for n in range(N):
    if sum(oB[:(n+1)])>=M:
        if n>0:
            print(sum(oAs[:n])+(oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        else:
            print((oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        exit()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M=map(int,input().split())
A=[None]*N
B=[None]*N
for n in range(N):
    A[n],B[n]=map(int,input().split())
orderA=np.argsort(A)
oAs=[A[i]*B[i] for i in orderA]
oB=[B[i] for i in orderA]
for n in range(N):
    if sum(oB[:(n+1)])>=M:
        if n>0:
            print(sum(oAs[:n])+(oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        else:
            print((oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        exit()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
A=[None]*N
B=[None]*N
for n in range(N):
    A[n],B[n]=map(int,input().split())
orderA=sorted(range(N), key=lambda k: A[k])
oAs=[A[i]*B[i] for i in orderA]
oB=[B[i] for i in orderA]
for n in range(N):
    if sum(oB[:(n+1)])>=M:
        if n>0:
            print(sum(oAs[:n])+(oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        else:
            print((oB[n]-sum(oB[:(n+1)])+M)*A[orderA[n]])
        exit()

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp = store[i]
    v = store[i][0]
    j = i - 1
    while j >= 0 and store[j][0] > v:
        store[j+1] = store[j]
        j -= 1
    store[j+1] = tmp

sumQ = 0
sumP = 0
for k in range(N):
    p = store[k][0]
    q = store[k][1]
    sumQ = sumQ + q
    sumP = sumP + p * q
    if M < sumQ:
        print(sumP-(sumQ-M)*p)
        break
    elif M == sumQ:
        print(sumP)
        break

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())
INF = 10** 9
# dp[i][j]: i+1番目までの商品で、j+1本の栄養ドリンクを買い集めるための最小コスト
dp = [[INF for i in range(M)] for j in range(N)]

for i in range(N):
  for j in range(M):
    array = []
    for k in range(min([j+1, B[i]])+1):
      array.append(dp[i-1][j-k] + A[i]*k if j>=k else A[i]*k)
    #dp[i][j] = min([dp[i-1][j], dp[i-1][j-1]+A[i], ... dp[i-1][j-B[i]] + A[i]*B[i]])
    dp[i][j] = min(array) if i > 0 else A[i]*(j+1)

print(dp[N-1][M-1])

Submission status: Time Limit Exceeded

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

R,S=M,0
while R!=0:
    mloc=A.index(min(A))
    AA=A.pop(mloc)
    BB=B.pop(mloc)
    if BB>=R:
        S+=AA*R;R=0
    else:
        S+=AA*BB;R-=BB
print(S)

Submission status: Time Limit Exceeded

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

a = 0
while True:
    s = AB.pop(0)
    if M > s[1]:
        M -= s[1]
        a += s[0] * s[1]
    else:
        a += s[0] * M
        break

print(a)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]
ab=[]
a=[]
b=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
    a.append(ab[i][0])
    b.append(ab[i][1])
cost=0
count=0
for i in range(n):
    amin = np.argmin(a)
    if count + b[amin] <= m:
        count += b[amin]
        cost += b[amin]*a[amin]
        del a[amin]
        del b[amin]
    else:
        cost += a[amin]*(m-count)
        break
print(cost)

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

dct = sorted(ABdict.items())
ls = []
for pricenumber in dct:
    for i in range (pricenumber[1]):
        ls.append(pricenumber[0])

print(sum(ls[:M]))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = dict()
p = 10000000000

for i in range(N):
    if p==1 and stores[p] >= M:
      break
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
while True:
    if p in stores:
        if M <= stores[p]:
            price += p * M
            break
        else:
            price += p * stores[p]
            M -= stores[p]
    p += 1
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = dict()
p = 10000000000

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi
    p = min(p, Ai)


price = 0
while True:
    if p in stores:
        if M <= stores[p]:
            price += p * M
            break
        else:
            price += p * stores[p]
            M -= stores[p]
    p += 1
print(price)

Submission status: Time Limit Exceeded

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

for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if Ai in stores:
        stores[Ai] += Bi
    else:
        stores[Ai] = Bi

price = 0
for i in range(1, 10000000000):
    if i in stores:
        if M <= stores[i]:
            price += i * M
            break
        else:
            price += i * stores[i]
            M -= stores[i]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if can_buy and Ai >= stores[-1][0]:
        continue
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
can_buy = False
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    if can_buy and Ai > stores[-1][0]:
        continue
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
            stock += Bi
            tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            can_buy = True
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stock = 0
    last_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai and tg_idx == -1:
          stock += Bi
          tg_idx = idx
        if stock < M:
            stock += s[1]
        else:
            last_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))
    if last_idx != -1:
        stores = stores[:last_idx+1]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

    stock = 0
    unuse_idx = -1
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
            break
    if unuse_idx != -1:
        stores = stores[:unuse_idx]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    stock = 0
    unuse_idx = -1
    tg_idx = -1
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
        if s[0] > Ai:
            if tg_idx == -1:
	            tg_idx = idx
    if unuse_idx != -1:
        stores = stores[:unuse_idx]
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

    stock = 0
    unuse_idx = -1
    for idx, s in enumerate(stores):
        if stock <= M:
            stock += s[1]
        else:
            unuse_idx = idx
    if unuse_idx != -1:
        stores = stores[:unuse_idx]

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split(" "))
stores = []
for i in range(N):
    Ai, Bi = map(int, input().split(" "))
    tg_idx = -1
    for idx, s in enumerate(stores):
        if s[0] > Ai:
            tg_idx = idx
            break
    if tg_idx != -1:
        stores.insert(tg_idx, (Ai, Bi))
    else:
        stores.append((Ai, Bi))

price = 0
for store in stores:
    if M <= store[1]:
        price += store[0] * M
        break
    else:
        price += store[0] * store[1]
        M -= store[1]
print(price)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int, input().split())
A = np.zeros(N)
B = np.zeros(N)
for _ in range(N):
    a, b = map(int, input().split())
    A[_] = a
    B[_] = b
sume = 0
while M > 0:
    tmp = A.argmin()#greed
    tmp2 = min(M,B[tmp]) #buy
    sume += A[tmp] * tmp2
    M -=  tmp2
    A =np.delete(A,tmp)
    B = np.delete(B,tmp)
print(int(sume))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int, input().split())
A = np.zeros(N)
B = np.zeros(N)
for _ in range(N):
    a, b = map(int, input().split())
    A[_] = a
    B[_] = b
sume = 0
while M > 0:
    tmp = A.argmin()#greed
    tmp2 = min(M,B[tmp]) #buy
    sume += A[tmp] * tmp2
    M -=  tmp2
    A[tmp] = 10**9+1
print(int(sume))

Submission status: Time Limit Exceeded

Solution code:
n,m = input().split()
n,m = int(n),int(m)
price = []
honsu = []
for i in range(n):
  a,b = input().split()
  price.append(int(a))
  honsu.append(int(b))
 
 
for j in range(n):
  k = j + 1
  while(k<n):
    if price[j] > price[k]:
      temp1,temp2 = price[j],honsu[j]
      price[j] = price[k]
      honsu[j] = honsu[k]
      price[k] = temp1
      honsu[k] = temp2
    k+=1
money = 0
l = 0
while m > 0:
  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]
  l += 1
print(money)

Submission status: Time Limit Exceeded

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

class value():
  def __init__(self, a, b):
    self.a = a
    self.b = b
  def __gt__(self, other):
    return self.a > other.a
  def __ge__(self, other):
    return self.a >= other.a

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

money = 0
i = 0

while True:
  v = V[i]
  if M <= v.b:
    break
  else:
    money += v.a * v.b
    M -= v.b
    i += 1
money += v.a * M
print(money)

Submission status: Time Limit Exceeded

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

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

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

while True:
  idx = A.index(min(A))
  a = A.pop(idx)
  b = B.pop(idx)
  if M <= b:
    break
  else:
    money += a * b
    M -= b
money += a * M
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())
match = 0
ans = 0
mini = 0

for j in range(n):
    mini = min(a)
    
    for k in range(b[a.index(mini)]):
        if m <= match:
            break
        ans += mini
        match += 1
    
    b.pop(a.index(mini))
    a.remove(mini)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
A,B = [],[]
for i in range(N):
  a,b = map(int,input().split())
  A += [a]
  B += [b]
AA = []
BB = []
while True:
  le = len(A)
  if le == 0:
    break
  else:
    for i in range(le):
      mini = min(A)
      if A[i] == mini:
        AA += [A[i]]
        BB += [B[i]]
        del A[i]
        del B[i]
        break
rest = M
cost = 0
while True:
  if rest - BB[0] <= 0:
    cost += rest * AA[0]
    break
  else:
    rest -= BB[0]
    cost += AA[0] * BB[0]
    del AA[0]
    del BB[0]
print(cost)

Submission status: Time Limit Exceeded

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

shops = []
for _ in range(N):
    ab = [int(c) for c in input().split()]
    shops.append(ab)

cost = 0
bought = 0
for i in range(N):
    if i < N - 1:
        target = shops[i][0]
        min_i = i
        for j in range(i+1, N):
            if shops[j][0] < shops[min_i][0]:
                min_i = j
        shops[min_i], shops[i] = shops[i], shops[min_i]

    k = 0
    while k < shops[i][1]:
        if bought == M:
            break
        cost += shops[i][0]
        k += 1
        bought += 1

    if bought == M:
        break

print(cost)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = input().split()
n, m = int(n), int(m)
a = np.array([int(x) for x in input().split()])
for i in range(1,n):
  a = np.append(a, [int(x) for x in input().split()])
a = a.reshape(n,2)
a = sorted(a, key=lambda x: x[0])
cost, i, thing = 0, 0, 0
while thing < m:
  if thing + a[i][1] < m:
    thing += a[i][1]
    cost += a[i][0]*a[i][1]
    i += 1
  else:
    cost += a[i][0]*(m-thing)
    thing = m
print(cost)

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())
def merge(rr):
    mid=len(rr[0])
    c=int(mid/2)
    if mid>1:
        left=merge([rr[0][:c],rr[1][:c]])
        right=merge([rr[0][c:],rr[1][c:]])
        ar=[]
        br=[]
        while len(left[0])!=0 and len(right[0])!=0:
            if left[0][0]<right[0][0]:
                ar.append(left[0].pop(0))
                br.append(left[1].pop(0))
            else:
                ar.append(right[0].pop(0))
                br.append(right[1].pop(0))
        if len(left[0])!=0:
            ar.extend(left[0])
            br.extend(left[1])
        elif len(right[0])!=0:
            ar.extend(right[0])
            br.extend(right[1])
        rr=[ar,br]
    return rr
rr=[a,b]
re=merge(rr)
tot=0
sum=0
while(1):
    if tot+re[1][0]<=m:
        tot+=re[1][0]
        sum+=re[0][0]*re[1][0]
        re[1].pop(0)
        re[0].pop(0)
        if len(re[1])==0:
            break
    else:
        sum+=re[0][0]*(m-tot)
        break
print(sum)

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

kane = 0
hon = 0
for i in range(N):
    if hon + AB[i][1] < M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        continue
    elif hon + AB[i][1] == M:
        hon += AB[i][1]
        kane += AB[i][0] * AB[i][1]
        print(kane)
        break
    else:
        for j in range(AB[i][1]):
            hon += 1
            kane += AB[i][0]
            if hon == M:
                print(kane)
                break

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

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

Submission status: Time Limit Exceeded

Solution code:
N, M= map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
count = 0
cost = 0
while count < M:
    pos = A.index(min(A))
    cost += A[pos] * min(B[pos],M-count)
    count += min(B[pos],M-count)
    A.pop(pos)
    B.pop(pos)
        
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N, M= map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
count = 0
cost = 0
while count < M:
    pos = A.index(min(A))
    if B[pos] <= M - count:
        count += B[pos]
        cost += A[pos] * B[pos]
        A.pop(pos)
        B.pop(pos)
    else:
        cost += A[pos] * (M - count)
        count = M
        
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N, M= map(int, input().split())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
count = 0
cost = 0
while count < M:
    cost += min(A)
    count += 1
    pos = A.index(min(A))
    B[pos] -= 1
    if B[pos] <= 0:
        A.pop(pos)
        B.pop(pos)
print(cost)

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_tmp, B_tmp] = list(map(int,input().split()))
    A[i] = A_tmp
    B[i] = B_tmp

tmp = M
ans = 0
while (tmp > 0):
        idx_tmp = A.index(min(A))
        # break condition
        if B[idx_tmp] >= tmp:
            ans += tmp*A[idx_tmp]
            tmp = 0
        else:
            ans += A[idx_tmp]*B[idx_tmp]
            tmp = tmp - B[idx_tmp]
            A.pop(idx_tmp)
            B.pop(idx_tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())
    shops = []
    ans = 0
    for i in range(n):
        shops.append(list(map(int, input().split())))
        shops.sort(key=lambda x:x[0])

    for shop in shops:
        price = shop[0]
        available = shop[1]
        if m - available > 0:
            ans += price * available
            m -= available
        else:
            ans += price * m
            break

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ab = []
for _ in range(n):
  a, b = map(int, input().split())
  ab.extend([a for _ in range(b)])
  
ab.sort()
print(sum(ab[:m]))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
l = []
for a,b in AB:
  l.extend([a]*b)
print(sum(sorted(l)[:M]))

Submission status: Time Limit Exceeded

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

count = []
price = 0
while sum(count) < m:
	for i in range(n):
		if sum(count) + a[i][1] < m:
			num = a[i][1]
		else:
			num = m - sum(count)
		price += num * a[i][0]
		count.append(num)
print price

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = map(int, raw_input().split())
a = np.empty((n,2), dtype=int)
for i in range(n):
	a[i,:] = map(int, raw_input().split())
a_sort = a[np.argsort(a[:,0])]

count = []
price = 0
while sum(count) < m:
	for i in range(n):
		if sum(count) + a_sort[i,1] < m:
			num = a_sort[i,1]
		else:
			num = m - sum(count)
		price += num * a_sort[i,0]
		count.append(num)
print price