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:

def C():
   NM = input().split() 
   N = int(NM[0])
   M = int(NM[1])
   A = []
   B = []
   ab_t = []
   for i in range(N):
       ab = input().split() 
       a = int(ab[0])
       b = int(ab[1])
       ab = [a,b]
       ab_t.append(ab)
   ab_sorted = sorted(ab_t, key=lambda a: a[0])
   
   money = 0
   m = M
   for x in ab_sorted:
       for y in range(x[1]):
           money += x[0]
           m -= 1
           if m == 0:
               print(money)
           

#   def buy(a, m, money):
#       for i,x in enumerate(a):
#           print('i')
#           print(i)
#           print('x')
#           print(x)
#           if x[1] >0:
#               a[i] = a[i][1] - 1
#               money += x[0]
#               buy(a, m, money)
#               if m==0:
#                   print(money)
           
    
    

if __name__ == '__main__':
    #A())
    #B()
    C()

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
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:
tmp = [int(i) for i in raw_input().split()]
N = tmp[0]
M = tmp[1]
sum = 0
buy = 0

alllist1 = []
alllist2 = []

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


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

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

    elif M == 0:
        break

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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]=float('inf')
                    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())
A,B=[],[]
for i in range(N):
    x,y=map(int,input().split())
    A.append(x)
    B.append(y)
k=M
c=0
while k>0:
    a=min(A)
    b=B[A.index(a)]
    k=k-b
    if k>0:
        c=c+a*b
    else:
        c=c+a*(k+b)
    A.remove(a)
    B.remove(b)
print(c)

Submission status: Time Limit Exceeded

Solution code:
n,m=[int(i) for i in input().split()]
min_money=[10000000000]
min_buy=[0]
for i in range(n):
    a,b=[int(i) for i in input().split()]
    if a<min_money[-1]:
        min_money.append(a)
        min_money.sort()
    if a in min_money:
        min_buy.insert(min_money.index(a),b)
ans=0
for i in range(len(min_buy)):
    if min_buy[i]>=m:
        ans+=min_money[i]*m
        break
    else:
        ans+=min_money[i]*min_buy[i]
        m-=min_buy[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
sum=0
A=[int(i) for i in range(N)]
B=[int(i) for i in range(N)]
for i in range(N):
  A[i],B[i]=map(int,input().split())
while True:
  K=B[A.index(min(A))]
  if K>=M:
    print(sum+min(A)*M)
    break
  else:
    sum+=K*min(A)
  M-=K
  A[A.index(min(A))]=max(A)+1

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)
    if cnt + B[min_index] <= M:
        ans += min_cost * B[min_index]
        cnt += B[min_index]
    else:
        ans += min_cost * (M - cnt)
        cnt = M
    del A[min_index]
    del B[min_index]
    
print(ans)

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:
    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]=1000000
    l[min_id]=100000
    if ct==M:
        break
print(money)

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)

arrayA = np.array(A)
arrayB = np.array(B)

for k in range(0, len(arrayA) - 1):
    for l in range(0, len(arrayA)- 1 - k) :
        idx = l
        if arrayA[idx] > arrayA[idx + 1]:
            tmpA = arrayA[idx]
            arrayA[idx] = arrayA[idx + 1]
            arrayA[idx + 1] = tmpA
            tmpB = arrayB[idx]
            arrayB[idx] = arrayB[idx + 1]
            arrayB[idx + 1] = tmpB

cnt = 0
sum = 0
flag = 0
for j in range(0, N):
    pay = arrayA[j]
    num = arrayB[j]
    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:
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):
    for i in range(n):
            if a[i]==min(a):
                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')

print(sum)

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)]
get = [0 for _ in range(n)]

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

ans = 0
need = copy.deepcopy(m)

while need > 0:
    minp = a.index(min(a))

    gen = min(b[minp], need)

    ans += a[minp] * gen
    get[minp] += gen

    need -= gen

    if get[minp] >= b[minp]:
        del a[minp]
        del b[minp]
        del get[minp]

print(ans)

Submission status: Time Limit Exceeded

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

alllist1 = []
alllist2 = []

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


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

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



print(sum)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
sum = 0
money = 0
A = list()
B = list()
for i in range(n):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))
for i in range(n):
    index = A.index(min(A))
    if(B[index] >= m - sum):
        money += A[index] * (m - sum)
        sum = m
        break
    else:
        sum += B[index]
        money += A[index]*B[index]
    del A[index]
    del B[index]
print(money)

Submission status: Time Limit Exceeded

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

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


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

Submission status: Time Limit Exceeded

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

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


while(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
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
            if b[i]<=0:
                a[i]=float('inf')

print(sum)

Submission status: Time Limit Exceeded

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

A = []
B = []
for n in range(N):
    num = input()
    a, b = [int(x) for x in num.split()]
    A.append(a)
    B.append(b)

count = 0
money = 0
while count < M:
    ind = A.index(min(A))

    if (M - count) > B[ind]:
        money += A[ind] * B[ind]
        count += B[ind]
    else:
        money += A[ind] * (M - count)
        count += B[ind]

    A.remove(min(A))
    B.pop(ind)

print(money)

Submission status: Time Limit Exceeded

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

bottles = 0
sum = 0
while(True):
    m = min(a, key=(lambda x: x[0]))
    
    if bottles + m[1] >= M:
        sum += (M - bottles) * m[0]
        break
    
    bottles += m[1]
    sum += m[0] * m[1]
    a.remove(m)
    
    
print(sum)

Submission status: Time Limit Exceeded

Solution code:
num_shop, num_drink_to_buy = map(int, input().split(' '))

list_price = []
for i in range(0, num_shop):
    price, availability = map(int, input().split(' '))
    list_price.extend([price for j in range(0, availability)])

list_price.sort()

print(sum(list_price[0:num_drink_to_buy]))
exit(0)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
sum = 0
money = 0
A = list()
B = list()
for i in range(n):
    a, b = input().split()
    A.append(int(a))
    B.append(int(b))
for i in range(n):
    index = A.index(min(A))
    if(B[index] >= m - sum):
        money += A[index] * (m - sum)
        sum = m
    else:
        sum += B[index]
        money += A[index]*B[index]
    if(sum == m):
        print(money)
        break
    del A[index]
    del B[index]

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
n = 1
count_A = []
count_B = []
while n <= N:
    Ai, Bi = map(int, input().split())
    count_A.append(Ai)
    count_B.append(Bi)
    n += 1

m = 0
sum = 0
flg = False
while True:
    mo = min(count_A)
    t = count_A.index(mo)
    subsum = 0
    for i in range(1, count_B[t] + 1):
        subsum += 1
        sum += 1
        if sum == M:
            flg = True
            break
    m += mo * subsum
    count_A.remove(mo)
    del count_B[t]
    if flg:
        break
print(m)

Submission status: Time Limit Exceeded

Solution code:
inp=list(map(int,input().split()))
hyou=[]
for i in range(inp[0]):
  kakaku= list(map(int,input().split()))
  for j in range(kakaku[1]):
    hyou.append(kakaku)
hyou=sorted(hyou)
nedan=0
for m in range(inp[1]):
  neda=hyou[m][0]
  nedan=nedan+neda
print(nedan)

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= [i for i, x in enumerate(al) if x == min(al)]
    lengh=len(k)
    pri=al[k[0]]
    for i in range(lengh):
        num=0
        num+=bl[k[i]]
        al[k[i]]=10**9+1
    have+=num
    yen+=pri*num
if have>m:
    yen-=(have-m)*pri
print(yen)

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=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
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
            if b[i]==0:
                a[i]=float('inf')

print(sum)

Submission status: Time Limit Exceeded

Solution code:
def unzip(li):
  return map(list, zip(*li))

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

for i in range(N):
  a,b = map(int, input().split())
  tmp_C[i] = (a,b)
  
C = sorted(tmp_C)
A, B = unzip(C)
ans = 0
count = 0
while(count < M):
  min_A = A[0]
  B_min = B[0]
  if count + B_min >= M:
    print(ans + min_A * (M - count))
    break
  else:
    ans += min_A * B_min
    count += B_min
    del A[0]
    del B[0]

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]
print(r)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
sum = 0
money = 0
A = list()
B = list()
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
for i in range(n):
    index = A.index(min(A))
    if(B[index] >= m - sum):
        money += A[index] * (m - sum)
        sum = m
    else:
        sum += B[index]
        money += A[index]*B[index]
    if(sum == m):
        print(money)
        break
    del A[index]
    del B[index]

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)]
get = [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(0, m):
    minp = a.index(min(a))
    get[minp] += 1

    ans += a[minp]

    if get[minp] >= b[minp]:
        del a[minp]
        del b[minp]
        del get[minp]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
 
N,M = sys.stdin.readline().strip().split()
N = int(N)
M = int(M)

A = []
B = []
for i in range(N):
    a,b = sys.stdin.readline().strip().split()
    A.append(int(a))
    B.append(int(b))
    
#print(A,B)

#print(A.index(min(A)))

num=0
money=0
num_tmp=0
while(num<M):
#    print("A!",A)
#    print("B!",B)
    if(len(A)>1):
        cheap_index = A.index(min(A))
        if(M-num<B[cheap_index]):
            num_tmp = M - num
            num += num_tmp
        else:
#            print("else num_tmp",B[cheap_index])
            num_tmp = B[cheap_index]
            num += num_tmp
        money += min(A) * num_tmp
        A.pop(cheap_index)
        B.pop(cheap_index)
#        print("num_tmp",num_tmp)
#        print("m,num", money,num)
    else:
        num_tmp = M - num
        num += num_tmp
        money += A[0] * num_tmp
#        print(money,num)
        
print(money)

Submission status: Time Limit Exceeded

Solution code:
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)

while(True):
    #最小値
    mins = min(price_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:
def unzip(li):
  return map(list, zip(*li))

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

for i in range(N):
  a,b = map(int, input().split())
  tmp_A.append(a)
  tmp_B.append(b)
  
C = sorted(zip(tmp_A,tmp_B))
A, B = unzip(C)
ans = 0
count = 0
while(count < M):
  min_A = A[0]
  B_min = B[0]
  if count + B_min >= M:
    print(ans + min_A * (M - count))
    break
  else:
    ans += min_A * B_min
    count += B_min
    del A[0]
    del B[0]

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
# while m>0:
for i in range(n):
    min_b = b[a.index(min(a))]
    min_a = a.index(min(a))
    if m - min_b > 0:
        m -= min_b
        ans +=  b.pop(min_a)*a.pop(min_a)
    else:
        ans +=  m*a.pop(min_a)
        m = 0
        print(ans)
        exit()

Submission status: Time Limit Exceeded

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

"""
Energy Drink Collector
"""

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:
        for _ in range(v[1]):
            l_price.append(v[0])

    # 買う。
    cost = 0
    for i in range(M):
        cost += l_price[i]

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


if __name__ == '__main__':
    main()

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,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:
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 LL==[]:
        print(x-y*(-1)*w)
        z=1
        break
    else:
        y-=LL[0][1]
        x+=LL[0][1]*LL[0][0]
        z=LL[0][1]*LL[0][0]
        w=LL[0][0]
        LL=LL[1:]
print(x-y*(-1)*w)

Submission status: Time Limit Exceeded

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

for i in range(1000000):
    min_index = a.index(min(a))
    if m - b[min_index] <=0:
        break
    m = m - b[min_index]
    ans += a[min_index]*b[min_index]
    del a[min_index]
    del b[min_index]

ans += m * a[min_index]
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 -= 1
  B[cnt2] -= 1
  r += A[cnt2]
print(r)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def a(input_string):
    N, M = [int(x) for x in input_string[0].split()]
    C = input_string[1:]
    temp = [string.split() for string in C]
    D = []
    for i in range(len(temp)):
        D.append([int(word) for word in temp[i]])
    #print(D)
    get_count = 0
    min_cost = 10000000000000000
    cost = 0
    D = sorted(D, key=lambda x: x[0])
    for i in range(N):
        for j in range(D[i][1]):
            get_count += 1
            cost += D[i][0]
            if get_count >= M:
                if cost < min_cost:
                    min_cost = cost
    return min_cost


def main():
    input_line = stdin.readlines()
    answer = a(input_line)
    print(answer)


if __name__ == '__main__':
    main()

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
                    if count>=m:
                        break
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
                    if count>=m:
                        break
            if b[i]==0:
                a[i]=float('inf')
                continue

print(sum)

Submission status: Time Limit Exceeded

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

a =[]
for i in range(n):
    a.append(ab[i][0])

b = []
for i in range(n):
    b.append(ab[i][1])

x = 0 #本数
y = 0 #金額

while m > x:
    if b[a.index(min(a))] > 0:
        y += min(a)
        b[a.index(min(a))] -= 1
        x += 1
    else:
        del b[a.index(min(a))]
        del a[a.index(min(a))]
        continue

print(y)

Submission status: Time Limit Exceeded

Solution code:
def findmax(ma, a,b):
	ma = a.index(max(a))
	if b[ma] > 0:
		b[ma] -= 1
		return ma,a,b
	else:
		a.pop(ma)
		b.pop(ma)
		return findmax(ma, a, b)

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

a = []
b = []

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

ma = a.index(max(a))
total = sum([a[j]*b[j] for j in range(n)])
deltarget = sum(b) - m

while deltarget > 0:
	ma, a, b = findmax(ma, a, b)
	total -= a[ma]
	deltarget -= 1
	
print(total)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
number, value = 0, 0
A_list, B_list = [], []
for i in range(N):
    A, B = map(int, input().split())
    A_list.append(A)
    B_list.append(B)
for i in range(N):
    A_value = min(A_list)
    A_index = A_list.index(min(A_list))
    value += A_value * B_list[A_index]
    number += B_list[A_index]
    del A_list[A_index]
    del B_list[A_index]
    if number > M:
        sabun = number - M
        value -= sabun * A_value
        break
print(value)

Submission status: Time Limit Exceeded

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

while True:
    min_index = a.index(min(a))
    if m - b[min_index] <=0:
        break
    m = m - b[min_index]
    ans += a[min_index]*b[min_index]
    del a[min_index]
    del b[min_index]

ans += m * a[min_index]
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(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
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
            if b[i]==0:
                a[i]=float('inf')
                continue

print(sum)

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
for p in range(n):
    ind = prise.index(min(prise))
    cost += min(prise) * conte[ind]
    ki += conte[ind]
    temp = min(prise)
    conte.pop(ind)
    prise.pop(ind)
    
    if ki >= m:
        if ki-m > 0:
            cost = cost - (ki-m)*temp
        break
    
print(cost)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
# while m>0:
for i in range(n):
    if m - b[a.index(min(a))] > 0:
        m -= b[a.index(min(a))]
        ans +=  b.pop(a.index(min(a)))*a.pop(a.index(min(a)))
    else:
        ans +=  m*a.pop(a.index(min(a)))
        m = 0
        print(ans)
        exit()

Submission status: Time Limit Exceeded

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

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

drink = 0
money = 0
while drink < m:
    price = min(al)
    kosu = bl[al.index(price)]
    money += price * kosu
    drink += kosu
    al.remove(price)
    bl.remove(kosu)
    if drink > m:
        money -= (drink-m)*price

print(money)

Submission status: Time Limit Exceeded

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

price_howmany = dict(price_howmany)

def solve():
    price = 0
    many = 0
    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 = 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))
    cost += min(prise) * conte[ind]
    ki += conte[ind]
    temp = min(prise)
    conte.pop(ind)
    prise.pop(ind)
    
    if ki >= m:
        if ki-m > 0:
            cost = cost - (ki-m)*temp
        break
    
print(cost)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a = []
b = []
ans = 0
for i in range(n):
    tempa,tempb = map(int,input().split())
    a.append(tempa)
    b.append(tempb)
while m>0:
    if m - b[a.index(min(a))] > 0:
        m -= b[a.index(min(a))]
        ans +=  b.pop(a.index(min(a)))*a.pop(a.index(min(a)))
    else:
        ans +=  m*a.pop(a.index(min(a)))
        m = 0
    # test = a.pop(a.index(min(a)))
print(ans)

Submission status: Time Limit Exceeded

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

@author: iwata
"""

N,M = map(int, input().split())
numlist =[]
num = 0

for i in range(N):
    A,B = map(int, input().split())
    for j in range(B):
        numlist.append(A)

numlist.sort()


for k in range(M):
    num += numlist[k]
    
print(num)

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
                else:
                    sum+=(m-count)*a[i]
                    b[i]-=m-count
                    count+=m-count
            if b[i]==0:
                a[i]=float('inf')
                continue

print(sum)