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:
b=list(map(int,input().split()))
LL=[]
for i in range(b[0]):
    LL.append(list(map(int,input().split())))
LL.sort(key=lambda x: x[0])
x=0
z=0
y=b[1]
while y>=0 and not LL==[]:
    if y<=LL[0][1]:
        print(x+LL[0][0]*y)
        break
    else:
        y-=LL[0][1]
        x+=LL[0][1]*LL[0][0]
        LL=LL[1:]

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]
        del A[minidx]
        del B[minidx]
    elif(M - bought < B[minidx]):
#        print("buy = {}, price = {}".format(M - bought, A[minidx]))
        price = price + A[minidx] * (M - bought)
        bought = M
        break

print(price)

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
i = 0
while i < len(a):
  if b>M or b==M:
    break
  res = res + a[i]*dic[a[i]]
  b += dic[a[i]]
  i+=1
res = res-(b-M)*a[(i-1)]
print(res)

Submission status: Time Limit Exceeded

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

counter=0
amount=0
flag=0
for i in range(N[0]):
    v = drinks[i]
    x = drinks[i][0]
    j = i-1
    while(j >= 0 and drinks[j][0]>x):
        drinks[j+1] = drinks[j]
        j -= 1
    drinks[j+1] = v
    x = drinks[j+1][0]

for i in range(N[0]):
    if flag==1:
        break
    while(drinks[i][1]!=0):
        drinks[i][1] -=1
        counter +=1
        amount += drinks[i][0]
        if counter==N[1]:
            flag=1
            break
print(amount)

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

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

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]=tuple(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:
n,m = map(int,input().split())
# A_2=0
# B_2=0
list_A=[]
list_B=[]
sum_num=0
for i in range(n):
    A,B = map(int,input().split())
    list_A.append(A)
    list_B.append(B)

for i in range(n):
    minj = i
    for j in range(i,n):
        if list_A[j]<list_A[minj]:
            minj=j
    hokan=list_A[i]
    list_A[i]=list_A[minj]
    list_A[minj]=hokan
    hokan_b=list_B[i]
    list_B[i]=list_B[minj]
    list_B[minj]=hokan_b

list_AB = []
for i in range(n):
    list_AB.append( (list_A[i], list_B[i]))

list_AB.sort()
list_A , list_B = zip(*list_AB)
# list_A.sort()
# list_B.sort()
# print(list_A)
# print(list_B)


m_1=m
for i in range(n):
    m_2=m_1
    m_1=m_1-int(list_B[i])
    if m_1<0:
        sum_num=sum_num + int(list_A[i])*m_2
    else:
        sum_num=sum_num +int(list_A[i])*int(list_B[i])
    #print(sum_num)
    #print("m_1",m_1,"m_2",m_2)
    if m_1<0:
        break

print(sum_num)

Submission status: Time Limit Exceeded

Solution code:
lx = list(map(int,input().split(" ")))
#la = [li[0]][li[1]]
la = []
cnt = 0

for i in range(0, lx[0]):
    la.append(list(map(int,input().split(" "))))

print("setok")
coin = 0
bottle = 0
for i in range(1, 10 ** 9):
    for j in range(0, lx[0]):
        if (la[j][0] == i):
            while (bottle <= lx[1] and la[j][1] > 0):
                coin += la[j][0]
                bottle += 1
                la[j][1] - 1
    if (bottle == lx[1]):
        break

Submission status: Time Limit Exceeded

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

for i in range(N):
    shop = list(map(int,input().split()))
    for j in range(shop[1]):
        shop_list.append(shop[0])
        
print(sum(sorted(shop_list)[0:M]))

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
cnt = 0
num = 0
while cnt < M:
    price += minprice
    cnt += 1
    num += 1
    if num == x[number][1] and (len(x) != 1):
        x = np.delete(x, number, 0)
        minprice = min(x[0:,0])
        number = np.argmin(x[0:,0])
        num = 0
print(price)

Submission status: Time Limit Exceeded

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

for i in range(N):
    shop = list(map(int,input().split()))
    price = (shop[0])
    num = (shop[1])
    for j in range(num):
        shop_list.append(price)
        
print(sum(sorted(shop_list)[0:M]))

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
A = []
B = []
ans = 0
for _ in range(N):
    i = list(map(int,input().split()))
    A.append(i[0])
    B.append(i[1])
while M != 0:
    ind_ = A.index(min(A))
    if M - B[ind_] > 0:
        M -= B[ind_]
        ans += A[ind_]*B[ind_]
        B[ind_] -= B[ind_]
    else:
        ans += A[ind_]*M
        break
    if B[ind_] <= 0:
        B.pop(ind_)
        A.pop(ind_)
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, i])
    b.append([y, i])
a.sort()
ans = 0
idx = 0
while True:
    if m <= 0:
        break
    i = a[idx][1]
    for j in range(len(b)):
        if b[j][1] == i:
            kosuu = b[j][0]
    if kosuu <= m:
        ans += kosuu * a[idx][0]
        m -= kosuu
        idx += 1
    else:
        ans += m * a[idx][0]
        m = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
A = []
B = []
s = 0
cost = 0
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
while s < m:
    if s + B[A.index(min(A))] <= m:
        cost += B[A.index(min(A))] * min(A)
        s += B[A.index(min(A))]
        
        B.remove(B[A.index(min(A))])
        A.remove(min(A))
    else:
        cost += min(A) * (m - s)
        s = m
        

print(cost)

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
i = 0
while i < N:
  if b>M or b==M:
    break
  res = res + a[i]*dic[a[i]]
  b += dic[a[i]]
  i+=1
res = res-(b-M)*a[(i-1)]
print(res)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

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

for _ in range(N):
    AB = list(map(int,input().split()))
    A.append(AB[0])
    B.append(AB[1])

A=np.array(A)
B=np.array(B)
Money = 0
Drink = 0
while True:
    minidx = np.argmin(A)
    Money += A[minidx]*B[minidx]
    Drink += B[minidx]
    if Drink >= M:
        Money = Money - (A[minidx]*(Drink - M))
        break
    A = np.delete(A, minidx)
    B = np.delete(B, minidx)
    
print(Money)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
a, b = [], []
ans = 0
INF = float('inf')
for n in range(N):
    tmp1, tmp2 = map(int, input().split())
    a.append(tmp1)
    b.append(tmp2)

count = 0
while count < M:
    mindex = a.index(min(a))
    buycount = min(b[mindex], M - count)
    count += buycount
    ans += a[mindex]*buycount
    a[mindex] = INF
print(ans)

Submission status: Time Limit Exceeded

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

AB=[]
for i in range(N):
  inp = input().split()
  AB = AB + [[int(inp[0]),int(inp[1])]]

AB = sorted(AB, key=lambda x: x[0])

rem = M
cost = 0
i = 0
while rem>0:
  if AB[i][1]<=rem:
    cost = cost + AB[i][0]*AB[i][1]
    rem = rem - AB[i][1]
    i = i+1
  else:
    cost = cost + AB[i][0]*rem
    rem = 0
  
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while ct<M:
    min_id=l.index(min(l))
    if ct+ab[min_id][1]<M:
        money+=ab[min_id][0]*ab[min_id][1]
        ct+=ab[min_id][1]
        l[min_id]=10000000000
    else:
        for i in range(ab[min_id][1]):
            money+=l[min_id]
            ct+=1
            if ct==M:
                break
        l[min_id]=100000000000
        if ct==M:
            break
print(money)

Submission status: Time Limit Exceeded

Solution code:
def mergesort(a, left, right):
    if left + 1 < right:
        mid = int((left + right)/2)
        mergesort(a, left, mid)
        mergesort(a, mid, right)
        merge(a, left, mid, right)
    return a

def merge(a, left, mid, right):
    n1 = mid - left
    n2 = right - mid
    L = [a[left + i] for i in range(n1)]
    R = [a[mid + i] for i in range(n2)]
    L.append(1e10)
    R.append(1e10)
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            a[k] = L[i]
            i += 1
        else:
            a[k] = R[j]
            j += 1

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 = mergesort(a_list, 0, 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 = []
r = 0
for i in range(N):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
while M > 0:
  cnt = 1000000001
  cnt2 = 0
  for i in range(N):
    if (A[i] < cnt) and (B[i] != 0):
      cnt = A[i]
      cnt2 = i
  M -= B[cnt2]
  r += A[cnt2]*B[cnt2]
  B[cnt2] = 0
  if M < 0:
    r -= abs(M)*A[cnt2]
  A[cnt2] = 0
print(r)

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

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

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
A=[]
B=[]
money=0
maxa=0
maxb=0
for i in range(N):
  x,y=map(int,input().split())
  if maxa<x:
    maxa=x
    maxb=i
  A.append(x)
  B.append(y)
for i in range(N):
  lowest=maxb
  low=maxa
  for j in range(N):
    if (low>A[j] and A[j]!=0):
      lowest=j
      low=A[j]
  if B[lowest]>M:
    money+=M*A[lowest]
    M-=B[lowest]
    break
  else:
    money+=B[lowest]*A[lowest]
    M-=B[lowest]
  A[lowest]=0
print(money)

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
A = []
B = []
ans = 0
for _ in range(N):
    i = list(map(int,input().split()))
    A.append(i[0])
    B.append(i[1])
while M != 0:
    ind_ = A.index(min(A))
    if M - B[ind_] > 0:
        M -= B[ind_]
        ans = ans + A[ind_]*B[ind_]
        B[ind_] -= B[ind_]
    else:
        ans = ans + A[ind_]*M
        M = 0
        B[ind_] = 0
    if B[ind_] <= 0:
        B.pop(ind_)
        A.pop(ind_)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# abc121_c

"""
Energy Drink Collector
"""
test = False


def main():
    """
    とにかく安い方からM本になるまで買い続ける。
    """
    N, M = map(int, input().split())
    l = []

    for _ in range(N):
        # 安い順に、値段だけのリストをつくる。[100, 100, 100, 110, 120, 120, ...]
        tempA, tempB = map(int, input().split())
        l.extend([tempA] * tempB)

    # 安い順に並べる
    l.sort()
    if test:
        print(l)

    # 買う。
    cost = sum(l[0:M])

    # 合計金額を出力
    print(cost)


if __name__ == '__main__':
    main()

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

for i in range(n):
  ablist = mlist[i]
  if count+ablist[1] <= m:
    count += ablist[1]
    cost += ablist[0]*ablist[1] 
  else:
    for j in range(ablist[1]):
      count += 1
      if count <= m:
        cost += ablist[0]
      else:
        break_t = True
        break
    if break_t:
      break
print(cost)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

for _ in range(N):
    AB = list(map(int,input().split()))
    A.append(AB[0])
    B.append(AB[1])

Money = 0
Drink = 0
while True:
    minidx = np.argmin(A)
    Money += A[minidx]*B[minidx]
    Drink += B[minidx]
    if Drink >= M:
        Money = Money - (A[minidx]*(Drink - M))
        break
    A = np.delete(A, minidx)
    B = np.delete(B, minidx)
    
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())

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
cost = 0
li =[]
for i in range(n):
  a,b = map(int,input().split())
  for j in range(b):
  	li.append(a)
li = sorted(li)
for k in range(m):
  cost = cost + li[k]
print(cost)

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

while(m):
    if len(a) > 1:
        ind = a.index(min(a))
    else:
        ind = 0
    while(b[ind]):
        b[ind] -= 1
        ans += min(a)
        m -= 1
        if (b[ind] == 0):
            a[ind] = 1000000000
            if len(a) > 1:
                ind = a.index(min(a))
            else:
                ind = 0
        if (m == 0):
            break
print(ans)

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 = list(map(int, input().split()))
    drink.append(Drink)
    drink.sort()

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:
import copy
n,num = map(int,input().split())
price_list=[]
num_list=[]
money=0
for i in range(n):
    p,n = map(int,input().split())
    price_list.append(p)
    num_list.append(n)

sort_list = copy.deepcopy(price_list)
sort_list.sort()
    
for mins in sort_list:

    min_num_list = [i for i, x in enumerate(price_list) if x == mins]

    for min_num in min_num_list:
        n = num_list[min_num]

        if n < num:
            #全部買い
            num -= n
            money += n*price_list[min_num]
            price_list[min_num] = pow(10,9) # 除外

        else:
            #足りない文だけ
            money += num*price_list[min_num]
            num=0
            break
        
    if num == 0:
        break
print(money)

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:
N,M = list(map(int,input().split()))
A = []
B = []
ans = 0
for _ in range(N):
    i = list(map(int,input().split()))
    A.append(i[0])
    B.append(i[1])
while M != 0:
    ind_ = A.index(min(A))
    if M - B[ind_] >= 0:
        M -= B[ind_]
        ans = ans + A[ind_]*B[ind_]
        B[ind_] -= B[ind_]
    else:
        ans = ans + A[ind_]*M
        M = 0
        B[ind_] = 0
    if B[ind_] <= 0:
        B.pop(ind_)
        A.pop(ind_)
print(ans)

Submission status: Time Limit Exceeded

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

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

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(int, input().split())))
    A.append(a)
    B.append(b)

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

Submission status: Time Limit Exceeded

Solution code:
init = input().split(' ')
init = [int(i) for i in init]
n,m= init[0],init[1]

ab = []

try:
	while True:
		inp1 = input().split(' ')
		inp1 = [int(i) for i in inp1]
		ab.append([inp1[0],inp1[1]])
except:
	pass

ab.sort()
total = sum([ab[j][0]*ab[j][1] for j in range(n)])
deltarget = sum([ab[j][1] for j in range(n)]) - m

while deltarget > 0:
	if ab[len(ab)-1][1]>0:
		total -= ab[len(ab)-1][0]
		ab[len(ab)-1][1] -= 1
		deltarget -= 1
		
	else:
		ab.pop(len(ab)-1)

print(total)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import numpy as np

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

ttl = 0
nokori = M

i = np.array(i)

while nokori > 0 :
    midx = np.argmin(i[:,0])
    
    k = i[midx,0]
    n = i[midx,1]
    
    if n < nokori:
        S = k * n
        X = n
    else:
        S = k * nokori
        X = nokori
    
    k = i[midx,0]
    n = i[midx,1]
    
    ttl = ttl + S
    nokori = nokori - X

    i = np.delete(i,midx,axis=0) 

print(ttl)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
A = []
B = []
ans = 0
for _ in range(N):
    i = list(map(int,input().split()))
    A.append(i[0])
    B.append(i[1])
while M != 0:
    if M - B[A.index(min(A))] >= 0:
        M -= B[A.index(min(A))]
        ans = ans + A[A.index(min(A))]*B[A.index(min(A))]
        B[A.index(min(A))] -= B[A.index(min(A))]
    else:
        ans = ans + A[A.index(min(A))]*M
        M = 0
        B[A.index(min(A))] = 0
    if B[A.index(min(A))] <= 0:
        B.pop(A.index(min(A)))
        A.pop(A.index(min(A)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:

n, m = map(int, input().split())
sumans = 0
ans = 0

list = [[0 for i in range(2)] for j in range(n)]
#print(list)

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

#print(sorted(list))
	
list = sorted(list)

for i in range(n):
	for j in range(int(list[i][1])):
		sumans += list[i][0]
		ans += 1
		if ans == m:
			print(sumans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while ct<M:
    min_id=l.index(min(l))
    for i in range(ab[min_id][1]):
        money+=l[min_id]
        ct+=1
        if ct==M:
            break
    ab[min_id][0]=100000000000
    l[min_id]=100000000000
    if ct==M:
        break
print(money)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())
A_list = []
B_list = []
for i in range(N):
    AB = list(map(int,input().split()))
    A_list.append(AB[0])
    B_list.append(AB[1])
ans = 0
for i in range(1000):
    if B_list[A_list.index(min(A_list))] < M:
        ans += min(A_list) * B_list[A_list.index(min(A_list))]
        M -= B_list[A_list.index(min(A_list))]
        m = A_list.index(min(A_list))
        A_list.pop(m)
        B_list.pop(m)
    else:
        ans += min(A_list) * M
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# abc121_c

"""
Energy Drink Collector
"""
test = False


def main():
    """
    とにかく安い方からM本になるまで買い続ける。
    """
    N, M = map(int, input().split())
    l = []

    for _ in range(N):
        # [値段, 在庫本数] の2xNリストをつくる。
        l.append(list(map(int, input().split())))

    # 安い順に並べる
    l.sort()
    l_price = []

    # 安い順に、値段だけのリストをつくる。[100, 100, 100, 110, 120, 120, ...]
    for v in l:
        l_price.extend([v[0]] * v[1])
        # for _ in range(v[1]):
            # l_price.append(v[0])

    if test:
        print(l_price)

    # 買う。
    cost = sum(l_price[0:M])

    # 合計金額を出力
    print(cost)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while True:
    min_id=l.index(min(l))
    for i in range(ab[min_id][1]):
        money+=l[min_id]
        ct+=1
        if ct==M:
            break
    ab[min_id][0]=100000000000
    l[min_id]=100000000000
    if ct==M:
        break
print(money)

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(count<m):
    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
                    a[i]=1000000000
                    break
                else:
                    sum+=(m-count)*a[i]
                    count+=m-count
                    break

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
A = []
B = []
ans = 0
for _ in range(N):
    i = list(map(int,input().split()))
    A.append(i[0])
    B.append(i[1])
#print(min(A),'min')
#print(A.index(min(A)),'index')
while M != 0:
    if M - B[A.index(min(A))] >= 0:
        M -= B[A.index(min(A))]
        ans = ans + A[A.index(min(A))]*B[A.index(min(A))]
        B[A.index(min(A))] -= B[A.index(min(A))]
    else:
        ans += min(A)
        M -= 1
        B[A.index(min(A))] -= 1
    if B[A.index(min(A))] <= 0:
        B.pop(A.index(min(A)))
        A.pop(A.index(min(A)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while True:
    min_id=l.index(min(l))
    for i in range(ab[min_id][1]):
        money+=l[min_id]
        ct+=1
        if ct==M:
            break
    ab[min_id][0]=-1
    l[min_id]=10000000000
    if ct==M:
        break
print(money)

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(count<m):
    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
                    a[i]=1000000000
                    break
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
                    break

print(sum)

Submission status: Time Limit Exceeded

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

while sum_p >= m:
    ind = prise.index(max(prise))
    if conte[ind] >= (sum_p - m):
        suma = suma - (sum_p-m)*prise[ind]
        break
    else:
        suma = suma - conte[ind]*prise[ind]
        sum_p -= conte[ind]
        if sum_p == m:
            break
    prise.pop(ind)
    conte.pop(ind)
print(suma)

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

for i in range(n):
  ablist = mlist[i]
  if count+ablist[1] <= m:
    count += ablist[1]
    cost += ablist[0]*ablist[1] 
  else:
    for j in range(ablist[1]):
      count += 1
      if count <= m:
        cost += ablist[0]
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for l in range(N)]
ct=0
money=0
l=[]
for i in range(N):
    l.append(ab[i][0])
while True:
    min_id=l.index(min(l))
    for i in range(ab[min_id][1]):
        money+=l[min_id]
        ct+=1
        if ct==M:
            break
    ab[min_id][0]=-1
    l[min_id]=100000
    if ct==M:
        break
print(money)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A_list = []
for i in range(N):
    A, B = map(int, input().split())
    A_list += [A for i in range(B)]
A_list.sort()
value = sum(A_list[0:M])
print(value)

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))  # min shop
  if B[min_i] <= M-drink:  # buy all drinks
    drink += B[min_i]
    ans += A[min_i]*B[min_i]
    del A[min_i]
    del B[min_i]
  else:  # buy some drinks
    ans += A[min_i]*(M-drink)
    drink = M
  
print(ans)

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

ab_list = sorted(ab_list)

buy = 0
money = 0
j = 0
lst = []

for i in range(n):
    lst.append(ab_list[n - i - 1][1])
    b_sum = sum(lst)

while (buy < m):
    buy += ab_list[j][1]
    money += ab_list[j][0] * ab_list[j][1]
    j += 1

print(money-(ab_list[j-1][0]*(buy-m)))