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:
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
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

Submission status: Time Limit Exceeded

Solution code:
def quicksort(lst):
	if lst == []: return []
	elif len(lst) == 1: return lst
	else:
		pivot = lst[0][0]
		leftlist = []
		rightlist = []
		for i in range(1, len(lst)):
			if lst[i][0] < pivot:
				leftlist.append(lst[i])
			else:
				rightlist.append(lst[i])
		newleft = quicksort(leftlist)
		newright = quicksort(rightlist)
		newleft.append(lst[0])
		newleft.extend(newright)
		return newleft

N, M = map(int, raw_input().split())
drinkprice = []
drinkamount = []
for i in range(0, N):
	p, a = map(int, raw_input().split())
	if p in drinkprice:
		drinkindex = drinkprice.index(p)
		drinkamount[drinkindex] += a
	else:
		drinkprice.append(p)
		drinkamount.append(a)
drinklist = []
for i in range(0, len(drinkprice)):
	drinklist.append([drinkprice[i], drinkamount[i]])	
	
drinklist = quicksort(drinklist)

sum = 0
drink = M
for i in range(0, len(drinklist)):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

Submission status: Time Limit Exceeded

Solution code:
def quicksort(lst):
	if lst == []: return []
	elif len(lst) == 1: return lst
	else:
		pivot = lst[0][0]
		leftlist = []
		rightlist = []
		for i in range(1, len(lst)):
			if lst[i][0] < pivot:
				leftlist.append(lst[i])
			else:
				rightlist.append(lst[i])
		newleft = quicksort(leftlist)
		newright = quicksort(rightlist)
		newleft.append(lst[0])
		newleft.extend(newright)
		return newleft

N, M = map(int, raw_input().split())
drinklist = []
for i in range(0, N):
	drinklist.append(map(int, raw_input().split()))
drinklist = quicksort(drinklist)

sum = 0
drink = M
for i in range(0, N):
	if drink < drinklist[i][1]:
		sum += drink * drinklist[i][0]
		break
	else:
		sum += drinklist[i][1] * drinklist[i][0]
		drink -= drinklist[i][1]

print sum

Submission status: Time Limit Exceeded

Solution code:
base = list(map(int,input().split()))
price = []
bottle = []
cost = 0

if base[0] == 1:
    store = list(map(int,input().split()))
    print(min(store[1],base[1])*store[0])

else:
    for i in range(base[0]):
        store = list(map(int,input().split()))
        price.append(store[0])
        bottle.append(store[1])

    while base[1]>0:
        if bottle[price.index(min(price))] < base[1]:
            cost = cost  + (bottle[price.index(min(price))]*min(price))
            base[1] = base[1]-bottle[price.index(min(price))]
            del bottle[price.index(min(price))]
            del price[price.index(min(price))]
        if bottle[price.index(min(price))] > base[1]:
            cost = cost  + base[1]*min(price)
            base[1] = 0
            
    print(cost)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
price=0
for i in range(n):
    a[i],b[i] = map(int, input().split())
while(m>0):
    num=a.index(min(a))
    if(b[num]<m):
        price+=b[num]*a[num]
        m-=b[num]
        del a[num]
        del b[num]
    else:
        price+=m*a[num]
        m=0
print(price)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

list_tmp = []
list_A = []
dict_AB = {}
for i in range(N):
    A, B = map(int, input().split())
    if dict_AB.get(A) is None:
        dict_AB[A] = B
    else:
        list_tmp.append((A, B))
    list_A.append(A)

list_A.sort()

ct = 0
money = 0
for i in list_A:
    A = i
    tmp = copy.deepcopy(list_tmp)
    if tmp:
        for j in list_tmp:
            if j[0] == A:
                B = j[1]
                list_tmp.remove((A, B))
                break
            else:
                B = dict_AB[A]
    else:
        B = dict_AB[A]

    money += A*B
    ct += B
    if ct >= M:
        money -= (ct - M)*A
        break

print(money)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

list_tmp = []
list_A = []
dict_AB = {}
for i in range(N):
    A, B = map(int, input().split())
    if dict_AB.get(A) is None:
        dict_AB[A] = B
    else:
        list_tmp.append((A, B))
    list_A.append(A)

list_A.sort()

ct = 0
money = 0
for i in list_A:
    A = i
    tmp = copy.deepcopy(list_tmp)
    if tmp:
        for j in list_tmp:
            if j[0] == A:
                B = j[1]
                list_tmp.remove((A, B))
                break
            else:
                B = dict_AB[A]
    else:
        B = dict_AB[A]
    for j in range(B):
        money += A
        ct += 1
        if ct == M:
            break
    if ct == M:
        break

print(money)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])
a.sort(key=lambda x:x[0])

cost=0
for j in range(M):
  if a[0][1]==0:
    a.pop(0)
  if a[0][1]>=1:
    a[0][1]-=1
    cost+=a[0][0]
print(cost)

Submission status: Time Limit Exceeded

Solution code:
import copy
List = []
N, M = (int(x) for x in input().split())
for i in range(N):
    a, b = (int(x) for x in input().split())
    List.append([a, b])

def merge(list):
    mid = len(list)
    if mid > 1:
        left = merge(list[:(mid//2)])
        right = merge(list[(mid//2):])
        list = []
        while len(left) != 0 and len(right) != 0:
            if left[0][0] < right[0][0]:
                list.append(left.pop(0))
            else:
                list.append(right.pop(0))
        if len(left) != 0:
            list.extend(left)
        elif len(right) != 0:
            list.extend(right)
    return list

num_of_drink, total_fee = 0, 0
List = copy.copy(merge(List))

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= List[i][1]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(List[i][1])
        temp_M += -List[i][1]
index = 0
for x in list_of_num:
    total_fee += List[index][0] * x
    index += 1
print(total_fee)

Submission status: Time Limit Exceeded

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

#sort main_list with sub_list
def merge(main_list, sub_list):
    mid = len(main_list)
    if mid > 1:
        left = merge(main_list[:(mid//2)], sub_list[:(mid//2)])
        right = merge(main_list[(mid//2):], sub_list[(mid//2):])
        main_list, sub_list = [], []
        while len(left[0]) != 0 and len(right[0]) != 0:
            if left[0][0] < right[0][0]:
                main_list.append(left[0].pop(0))
                sub_list.append(left[1].pop(0))
            else:
                main_list.append(right[0].pop(0))
                sub_list.append(right[1].pop(0))
        if len(left[0]) != 0:
            main_list.extend(left[0])
            sub_list.extend(left[1])
        elif len(right[0]) != 0:
            main_list.extend(right[0])
            sub_list.extend(right[1])
    return main_list, sub_list

num_of_drink, total_fee = 0, 0
A, B = copy.copy(merge(A, B)[0]), copy.copy(merge(A, B)[1])

temp_M = M
list_of_num = []
for i in range(N):
    if temp_M <= B[i]:
        list_of_num.append(temp_M)
        break
    else:
        list_of_num.append(B[i])
        temp_M += -B[i]
index = 0
for x in list_of_num:
    total_fee += A[index] * x
    index += 1
print(total_fee)

Submission status: Time Limit Exceeded

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

#sort main_list with sub_list
def merge(main_list, sub_list):
    mid = len(main_list)
    if mid > 1:
        left = merge(main_list[:(mid//2)], sub_list[:(mid//2)])
        right = merge(main_list[(mid//2):], sub_list[(mid//2):])
        main_list, sub_list = [], []
        while len(left[0]) != 0 and len(right[0]) != 0:
            if left[0][0] < right[0][0]:
                main_list.append(left[0].pop(0))
                sub_list.append(left[1].pop(0))
            else:
                main_list.append(right[0].pop(0))
                sub_list.append(right[1].pop(0))
        if len(left[0]) != 0:
            main_list.extend(left[0])
            sub_list.extend(left[1])
        elif len(right[0]) != 0:
            main_list.extend(right[0])
            sub_list.extend(right[1])
    return main_list, sub_list

num_of_drink, total_fee = 0, 0
A, B = copy.copy(merge(A, B)[0]), copy.copy(merge(A, B)[1])
for i in range(N):
    for j in range(B[i]):
        num_of_drink += 1
        total_fee += A[i]
        if num_of_drink == M:
            break
    else:
        continue
    break

print(total_fee)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split());a,b=[],[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa);b.append(bb)
#---c.sorted(a)---
c=a[:]
def swap(ab,ba,X):
  abc=X[ab]
  X[ab]=X[ba]
  X[ba]=abc
h=n
while 1:
  hh=c[:]
  if h>1:h=round(h//1.3)
  for i in range(n-h):
    if c[i]>c[i+h]:swap(i,i+h,c)
  if hh==c and h==1:break
#---------
s,ans=0,0
for i in c:
  j=a.index(i)
  k=min(b[j],m-s)
  s+=k
  ans+=a[j]*k
  a[j]=-1
  if m==s:break
print(ans)

Submission status: Time Limit Exceeded

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

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

remaining = M
cost = 0
while True:
  store = stores[getCheapest()]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    bought = store[1]
    store[1] = 0
    cost += store[0] * bought
    remaining -= bought

print(cost)

Submission status: Time Limit Exceeded

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

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

def buy(amount):
  store = stores[getCheapest()]
  if store[1] >= amount: # もしこの店で買いきれるなら
    return store[0] * amount
  else: #買い切れないなら
    bought = store[1]
    store[1] = 0
    return store[0] * bought + buy(amount - bought)
  
print(buy(M))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split());a,b=[],[]
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa);b.append(bb)
c=sorted(a)
s,ans=0,0
for i in c:
  j=a.index(i)
  k=min(b[j],m-s)
  s+=k
  ans+=a[j]*k
  a[j]=-1
  if m==s:break
print(ans)

Submission status: Time Limit Exceeded

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

Max = 0
list = []
for i in range(N):
    Max += A[i] * B[i]
    list.append(range(B[i]+1))

def SumOfList(l):
    ret = 0
    for i in l:
        ret += i
    return ret

def TotalFee(l):
    ret, index = 0, 0
    for z in l:
        ret += A[index] * z
        index += 1
    return ret

for l in itertools.product(*list):
    if SumOfList(l) == M and TotalFee(l) < Max:
        Max = TotalFee(l)

print(Max)

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

index_list = []
a = A.copy()
for i in range(N):
    index_list.append(a.index(min(a)))
    a[a.index(min(a))] = 10 ** 9

sum = 0
num = 0
for i in index_list:
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            sum += A[i]
            num += 1
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
import numpy as np
l = []
for i in [[a]*b for a,b in AB]:
  l.extend(i)

print(sum(sorted(l)[:M]))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, raw_input().split())
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, raw_input().split())
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for i in range(N):
    for j in range(AB[i][1]):
        if count < M:
            total += AB[i][0]
            count += 1
        else:
            break
                                                                                                                    
print total

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, raw_input().split())
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, raw_input().split())
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for i in range(N):
    for j in range(AB[i][1]):
        if count < M:
            total += AB[i][0]
            count += 1
            if count > M:
                exit()

print total

Submission status: Time Limit Exceeded

Solution code:
B = [float('inf')]*(10 ** 5)
A = [float('inf')]*(10 ** 5)
def main():
    accum = 0
    cost = 0
    N, M = map(int, input().split())
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    while accum < M:
         index = A.index(min(A))
         Aind = A.pop(index)
         Bind = B.pop(index)
         if accum + Bind > M:
             cost += Aind * (M - accum)
             accum = M
         else:
             accum += Bind
             cost += Aind * Bind
    print(cost)

main()

Submission status: Time Limit Exceeded

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

# # Bubble Sort
# start = 0
# for i in range(N-1):
#     for index in range(start, N-1):
#         if AB[index][0] > AB[index+1][0]:
#             AB[index], AB[index+1] = AB[index+1], AB[index]
#         else:
#             pass
#         start += 1

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

final = 0
sum_bottles = 0
while(M > sum_bottles):
    final += 1
    sum_bottles = 0
    for i in range(final):
        sum_bottles += AB[i][1]

cost = 0
sum_bottles = 0
for i in range(final):
    if i == final - 1:
        cost += AB[i][0] * (M - sum_bottles)
    else:
        cost += AB[i][0] * AB[i][1]
        sum_bottles += AB[i][1]

print(cost)

Submission status: Time Limit Exceeded

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

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

cost = 0
total_num = 0
num = 0
while True:
    index = A_list.index(min(A_list))
    num = B_list[index]
    if M > num:
        total_num += num
        cost += min(A_list)*num
        A_list.pop(index)
        B_list.pop(index)
        M -= num
    else:
        cost += min(A_list)*M
        break

print(cost)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
data=sorted([tuple(map(int,input().split())) for i in range(n)])
ans=0
while True:
  if m == 0:
    print(ans)
    exit()
  elif data[0][1]<=m:
    ans+=data[0][0]*data[0][1]
    m-=data[0][1]
    data=data[1:]
  else:
    ans+=data[0][0]*m
    m=0

Submission status: Time Limit Exceeded

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

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

bought = 0
money = 0
cheapest = getCheapest()

# M本買うまで繰り返す
while(bought < M):
  if (stores[cheapest][1] == 0):
    cheapest = getCheapest()
  money += stores[cheapest][0]
  stores[cheapest][1] -= 1
  bought += 1

# 最後にかかった金額を出力
print(money)

Submission status: Time Limit Exceeded

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

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

bought = 0
money = 0

# M本買うまで繰り返す
while(bought < M):
  index = getCheapest()
  money += stores[index][0]
  stores[index][1] -= 1
  bought += 1

# 最後にかかった金額を出力
print(money)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

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

ans = 0
while M > 0:
    if AB[0][1] == 0:
        AB = AB[1:]

    ans += AB[0][0]
    M -= 1

    AB[0][1] -= 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import numpy as np

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

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

ans = 0
while M > 0:
    if AB[0][1] == 0:
        AB = AB[1:]

    ans += AB[0][0]
    M -= 1

    AB[0][1] -= 1

print(ans)

Submission status: Time Limit Exceeded

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

money = 0

kakaku = []
honsuu = []
nokori_honsuu = M

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

while nokori_honsuu > 0:
	min_kakaku_pos = kakaku.index(min(kakaku))
	if honsuu[min_kakaku_pos] <= nokori_honsuu:
		money += honsuu[min_kakaku_pos] * kakaku[min_kakaku_pos]
		nokori_honsuu -= honsuu[min_kakaku_pos]
	else:
		money += nokori_honsuu * kakaku[min_kakaku_pos]
		nokori_honsuu -= nokori_honsuu
	kakaku.pop(min_kakaku_pos)
	honsuu.pop(min_kakaku_pos)
print(money)

Submission status: Time Limit Exceeded

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

S.sort()
m=0

for i in range(M):
    for j in range(N):
        if S[j][1]!=0:
            m+=S[j][0]
            S[j][1]-=1
            break

print(m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_list = []
for i in range(N):
    A, B = map(int, input().split())
    for j in range(B):
        A_list.append(A)
A_list = np.sort(A_list, kind='mergesort')
print(np.sum(A_list[:M]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

A_list = []
for i in range(N):
    A, B = map(int, input().split())
    for j in range(B):
        A_list.append(A)
A_list = np.cumsum(np.sort(A_list))
print(A_list[M-1])

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

n, m = map(int, input().split())
money = 0
li = sorted([list(map(int, input().split())) for _ in range(n)])

for j in range(n):
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

Submission status: Time Limit Exceeded

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

for i in range(n):
    li.append(list(map(int, input().split())))
li.sort()

while 0 < m:
    shop = li.pop(0)
    if m < shop[1]:
        money += m * shop[0]
        break
    money += shop[0] * shop[1]
    m -= shop[1]

print(money)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
a = []
for _ in range(n): 
    a.append(list(map(int, input().split())))
a.sort()
total = 0
while m > 0: 
    if a[0][1] > m: total += a[0][0]*m
    else: total += a[0][0]*a[0][1]
    m -= a[0][1]
    a.pop(0)
print(total)

Submission status: Time Limit Exceeded

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

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

list_price_and_energydrink = []

for i in range(N):
	A_i, B_i = map(int, input().split())
	list_shop_number_i = [A_i, B_i]
	list_price_and_energydrink.append(list_shop_number_i)
	
list_price = []
list_possible_number_drink = []

count_number_drink = 0
count_price_drink = 0

while count_number_drink < M:
	list_minimum_i = min(list_price_and_energydrink, key=key_func)
	
	if count_number_drink + list_minimum_i[1] > M:
		count_price_drink += list_minimum_i[0] * (M - count_number_drink)
		count_number_drink = M
	else:
		count_number_drink += list_minimum_i[1]
		count_price_drink += list_minimum_i[0] * list_minimum_i[1]	
	
	list_price_and_energydrink.remove(list_minimum_i)

print(count_price_drink)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
M = [[int(j) for j in input().split()] for i in range(n)]
cnt = 0
ans = 0  
a = [M[i][0] for i in range(n)]
b = [M[i][1] for i in range(n)]
while cnt < m:
     diff = m - cnt
     k = a.index(min(a))
     cnt += min(diff,b[k])
     ans += a[k]*(min(diff,b[k]))
     del a[k]
     del b[k]
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
  tmp_a, tmp_b = map(int, input().split())
  data.append((tmp_a, tmp_b))

sorted_data = sorted(data, key=lambda x: x[0])
  
buy_count = 0
money_count = 0

while buy_count < M:
  tmp_a = sorted_data[0][0]
  tmp_b = sorted_data[0][1]

  if buy_count + tmp_b < M:
    buy_count += tmp_b
    money_count += tmp_b * tmp_a
    sorted_data.pop(0)
  else:
    while buy_count < M:
      buy_count += 1
      money_count += tmp_a
      
print(money_count)

Submission status: Time Limit Exceeded

Solution code:
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)
  
buy_count = 0
money_count = 0

while True:
  min_a = min(A)
  index_a = A.index(min_a)
  value_b = B[index_a]
  
  while buy_count < M:
    if value_b == 0:  
      A.pop(index_a)
      B.pop(index_a)
      break
    value_b -= 1
    buy_count += 1
    money_count += A[index_a]
  
  if buy_count == M:
    break
  
print(money_count)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
costs_li=[]
costs_list=[]
limit_li=[]
total_li=[]
bought=0
pay=0
for i in range (1,n+1):
  cost,limit=map(int,input().split())
  costs_li.append(cost)
  costs_list.append(cost)
  limit_li.append(limit)
  total_li.append(cost*limit)
costs_li.sort()
low_li=[]
for j in range(0,n):
    for k in range (0,n):
        if costs_list[k]==costs_li[j]:
            low_li.append(k)
for l in range(0,n+1):
    if bought<m:
        pay=pay+total_li[low_li[l]]
        bought=bought+limit_li[low_li[l]]
    elif bought>m:
        pay=pay-costs_li[l-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
print(pay)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N,M = list(map(int,input().split()))

res_dict = {0:0}
for _ in range(N):
    #M本になるまでは買い続け、M本より多くなった場合は、価格の高いものから
    a,b = list(map(int,input().split()))
    cur_max_price = max(res_dict.keys())
    if sum(res_dict.values()) - M < 0 or a < cur_max_price:
        #追加操作
        if a in res_dict:
            res_dict[a] += b
        else:
            res_dict[a] = b
    decrease = sum(res_dict.values()) - M
    while decrease > 0:
        max_price = max(res_dict.keys())
        if decrease < res_dict[max_price]:
            res_dict[max_price] -= decrease
            break
        else:
            decrease -= res_dict[max_price]
            res_dict.pop(max_price)

print(sum([k * v for k,v in res_dict.items()]))

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp_key, tmp_val = map(int, input().split())
    if tmp_key in d:
        d[tmp_key] += tmp_val
    else:
        d[tmp_key] = tmp_val

cost = 0
while M > 0:
    tmp_key = min(d)
    tmp_val = d[tmp_key]
    if M - tmp_val < 0:
        cost += tmp_key * M
        break
    else:
        cost += tmp_key * tmp_val
        M -= tmp_val
        del d[tmp_key]

print(cost)

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp_key, tmp_val = map(int, input().split())
    if tmp_key in d:
        d[tmp_key] += tmp_val
    else:
        d[tmp_key] = tmp_val

cost = 0
while M > 0:
    tmp = min(d)
    if M - d[tmp] < 0:
        cost += tmp * M
        M = 0
    else:
        cost += tmp * d[tmp]
        M -= d[tmp]
        del d[tmp]

print(cost)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
AB = []
for i in range(0, N):
    AB.append(list(map(int, input().split())))
sum = 0
money = 0
start = 0
while sum<M:
    min = start
    for i in range(start, N):
        if AB[i][0]<=AB[min][0]:
            min = i
    tmp = AB[start]
    AB[start] = AB[min]
    AB[min] = tmp
    if sum+AB[start][1]<M:
        money = money+AB[start][0]*AB[start][1]
        sum = sum+AB[start][1]
    else:
        money = money+AB[start][0]*(M-sum)
        sum = M
    start = start+1
print("{}".format(money))

Submission status: Time Limit Exceeded

Solution code:
N, M=map(int, input().split())
A,B=[],[]
A_t,B_t=0,0
s = 0
r = 0
for i in range(N):
    A_t, B_t = map(int,input().split())
    A.append(A_t)
    B.append(B_t)
#自力でsort関数を作ればいいのでは？
for i in range(N-1):
    for j in range(N-i-1):
        if A[j] > A[j+1]:
            A[j], A[j+1] = A[j+1], A[j]
            B[j], B[j + 1] = B[j + 1], B[j]
for j in range(N):
    if M == 0:
        break
    elif M < B[j]:
        s += A[j] * M
        #print(B[j],M)
        break
    else:
        s += A[j] * B[j]
        M -= B[j]
        #print(s,M,A[j],B[j])
print(s)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    n,m = map(int,input().split())
    A = []
    B = []
    for i in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    ans = 0
    while 1:
        t = A.index(min(A))
        if m >= B[t]:
            ans += A[t] * B[t]
            m -= B[t]
        else:
            ans += A[t] * m
            m = 0
        if m == 0:
            break
        A.pop(t)
        B.pop(t)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def  qsort(l,l_y):
    if len(l) < 2:
        return(l,l_y)
    pivot = l[0]
    l_rest = l[1:]
    pivot_y = l_y[0]
    l_rest_y = l_y[1:]
    smaller = []
    larger = []
    smaller_y = []
    larger_y = []
    for i in range(len(l_rest)):
        if l_rest[i] < pivot:
            smaller.append(l_rest[i])
            smaller_y.append(l_rest_y[i])
        else:
            larger.append(l_rest[i])
            larger_y.append(l_rest_y[i])
    ret1,ret1_y  = qsort(smaller,smaller_y)
    ret2,ret2_y  = qsort(larger,larger_y)
    ret = ret1 + [pivot] + ret2
    ret_y = ret1_y + [pivot_y] + ret2_y
    return(ret,ret_y)
    
if __name__ == "__main__":
    n,m = map(int,input().split())
    A = []
    B = []
    for i in range(n):
        a,b = map(int,input().split())
        A.append(a)
        B.append(b)
    A,B = qsort(A,B)
    ans = 0
    k = 0
    while 1:
        if m >= B[k]:
            ans += A[k]*B[k]
            m -= B[k]
        else:
            ans += A[k]*m
            m = 0
        if m == 0:
            break
        k += 1
    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.append(a)
    B.append(b)
for i in range(n):
    for j in range(n-i-1):
        if A[j] > A[j+1]:
            t = A[j]
            A[j] = A[j+1]
            A[j+1] = t
            u = B[j]
            B[j] = B[j+1]
            B[j+1] = u
ans = 0
k = 0
while 1:
    if m >= B[k]:
        ans += A[k]*B[k]
        m -= B[k]
    else:
        ans += A[k]*m
        m = 0
    if m == 0:
        break
    k += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = map(int, input().split())
    A, B = [], []
    for i in range(N):
        a,b = map(int, input().split())
        A.append(a)
        B.append(b)
    # print(A, B)
    # 最小のコスト順に買っていけばよい
    # 同じコストのときはどうするか
    sum = 0
    count = 0
    flg = False
    for i in range(N):
        l = A.index(min(A)) # 最安値となっている要素
        for j in range(B[l]): # 買い占め
            count = count + 1
            sum = sum + A[l]
            if count == M:
                flg = True
                break
        A[l] = max(A) + 1 # 配列Aを書き換え
        if flg:
            break

    print(sum)
    # print(count)

main()

Submission status: Time Limit Exceeded

Solution code:
N_M = [int(x.strip()) for x in input().split()]
price_maxnum_list = [[int(i) for i in input().split()] for i in range(0, N_M [0])]
price_list = [i[0] for i in price_maxnum_list]
maxnum_list = [i[1] for i in price_maxnum_list]
if len(set(price_list)) ==1:
    print(price_list[0]*N_M[1])
else:
    total = 0
    nokori = N_M[1]
    while nokori > 0:
        ind = price_list.index(min(price_list))
        total += min(price_list) * min(maxnum_list[ind], nokori)
        nokori -= min(maxnum_list[ind], nokori)
        price_list.pop(ind)
        maxnum_list.pop(ind)
    print(total)