Problem:


Score : 300 points

Problem Statement

Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks.

There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each.

What is the minimum amount of money with which he can buy M cans of energy drinks?

It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks.

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

1 \leq B_i \leq 10^5

B_1 + ... + B_N \geq M

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Print the minimum amount of money with which Takahashi can buy M cans of energy drinks.

Sample Input 1

2 5
4 9
2 4

Sample Output 1

12

With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less.

Sample Input 2

4 30
6 18
2 5
3 10
7 9

Sample Output 2

130

Sample Input 3

1 100000
1000000000 100000

Sample Output 3

100000000000000

The output may not fit into a 32-bit integer type.



Sample input:
2 5
4 9
2 4


Sample output:
12

Submission status: Time Limit Exceeded

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

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

while m > 0:
    a, b = d[0]
    c += min(a * b, m * a)
    m -= b
    d = d[1:]

print(c)

Submission status: Time Limit Exceeded

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

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

ans = 0
while m > 0:
    minl = float("inf")
    for i in range(n):
        if minl > a[i] and b[i] != 0:
            minl = a[i]
    for i in range(n):
        if minl == a[i]:
            ans += min(a[i] * m, a[i] * b[i])
            m = max(m - b[i], 0)
            b[i] = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
num = []
sum = 0
for i in range(n):
    for _ in range(l[i][1]):
        num.append(l[i][0])
num = sorted(num)
for i in range(m):
    sum += num[i]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
num = []
for i in range(n):
    for _ in range(l[i][1]):
        num.append(l[i][0])
num = sorted(num)
print(sum(num[:m]))

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(i) for i in input().split())  
lis = []

for i in range(n):
  k, v= (int(i) for i in input().split())  
  lis += [k] * v

lis.sort()
print(sum(lis[:m]))

Submission status: Time Limit Exceeded

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

for x in a:
  lis += [x[0]] * x[1]

lis.sort()
print(sum(lis[:m]))

Submission status: Time Limit Exceeded

Solution code:
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        for i in range(b):
            total +=a
            m -=1
            if m==0:
                print(total)
                break

Submission status: Time Limit Exceeded

Solution code:
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        for i in range(b):
            total +=a
            m -=1
            if m==0:
                print(total)
                break

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
sorted_ab=sorted(ab, key=lambda x: x[0])
ans=0
i=0
for a, b in sorted_ab:
  for _ in range(b):
    if i < m:
      ans+=a
      i+=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)
ans = 0
tmp = 0
while tmp < M:
    num = min([M-tmp,B[A.index(min(A))]])
    tmp += num
    ans += num * min(A)
    ind = A.index(min(A))
    del A[ind]
    del B[ind]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
storeNum, canNum = input().split()
storeNum = int(storeNum)
canNum = int(canNum)
costs = [0] * storeNum
maxCanNumbers = [0] * storeNum

for i in range(storeNum):
    costs[i], maxCanNumbers[i] = input().split()
    costs[i] = int(costs[i])
    maxCanNumbers[i] = int(maxCanNumbers[i])

currentStoreHasMoreCans = False
totalPrice = 0

while canNum > 0 and not currentStoreHasMoreCans:
    currentStoreHasMoreCans = True
    minCostIndex = costs.index(min(costs))
    if canNum >= maxCanNumbers[minCostIndex]:
        totalPrice = totalPrice + costs[minCostIndex] * maxCanNumbers[minCostIndex]
        canNum = canNum - maxCanNumbers[minCostIndex]
    else:
        totalPrice = totalPrice + costs[minCostIndex] * canNum
        canNum = 0
    currentStoreHasMoreCans = False
    costs[minCostIndex] = 1000000001

print(totalPrice)

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)

new_A_list = []
for i in A_list:
    if i not in new_A_list:
        new_A_list.append(i)
    else:
        pass

sorted_new_A_list = sorted(new_A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(sorted_new_A_list[i])
        for j in index_B_list: 
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] < M:
            ans += sorted_new_A_list[i] * (count_list[i+1] - count_list[i])
        else:
            ans += sorted_new_A_list[i] * (M - count_list[i])
            break

print(ans)

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)

sorted_A_list = sorted(A_list)
new_sorted_A_list = []
for i in sorted_A_list:
    if i not in new_sorted_A_list:
        new_sorted_A_list.append(i)
    else:
        pass

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count_list = [0]
count = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
else:
    for i in range(N):
        index_B_list = counter(new_sorted_A_list[i])
        for j in index_B_list: 
            count += B_list[j]
        count_list.append(count)
            
        if count_list[i+1] < M:
            ans += new_sorted_A_list[i] * (count_list[i+1] - count_list[i])
        else:
            ans += new_sorted_A_list[i] * (M - count_list[i])
            break

print(ans)

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)

sorted_A_list = sorted(A_list)

def counter(x, l=A_list): #リストlに格納されている_xのインデックスを全て取得する
    return [i for i, _x in enumerate(l) if _x == x]


count = 0
gate = 0
ans = 0
if N == 1:
    ans = A_list[0] * M
    print(ans)
else:
    for i in range(N):
        index_B_list = counter(sorted_A_list[i])
        for j in index_B_list:
            count += B_list[j]
            if count <= M:
                ans += sorted_A_list[i] * B_list[j]
            else:
                if gate == 0: #ここを使用するのは答えを出す一回だけ
                    count -= B_list[j]
                    ans += sorted_A_list[i] * (M - count)
                    print(ans)
                    gate += 1

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = []
b = []
for _ in range(n):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)
ans = 0
cnt = 0
flag = 1
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i] < a[i-1]:
            a[i],a[i-1] = a[i-1],a[i]
            b[i],b[i-1] = b[i-1],b[i]
            flag = 1
for i in range(n):
    flag = 1
    while b[i] > 0 and cnt < m:
        ans += a[i]
        cnt += 1
        b[i] -= 1
        flag = 0
    if flag:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(x) for x in input().split())
a, b, b2, p = [], [], [], []
for i in range(N):
    o, t = (int(x) for x in input().split())
    a.append(o)
    b.append(t)
ans = 0
while M > 0:
    idx = a.index(min(a))
    n = b[idx]
    if M - n >= 0:
        ans += a[idx] * n
        M -= n
    else:
        ans += a[idx] * M
        M = 0
    del a[idx]
    del b[idx]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = (int(x) for x in input().split())
a, b, b2, p = [], [], [], []
for i in range(N):
    p.append([int(x) for x in input().split()])
    a.append(p[i][0])
    b.append(p[i][1])
ans = 0
while M > 0:
    idx = [i for i, x in enumerate(a) if x == min(a)]
    if len(idx) == 1:
        n = b[idx[0]]
        idx = idx[0]
    else:
        b2.append([i, b[i]] for i in idx)
        n = max(b2[:][1])
        idx = b2.index(b2[:][1] == n)
    if M - n >= 0:
        ans += a[idx] * n
        M -= n
    else:
        ans += a[idx] * M
        M = 0
    del a[idx]
    del b[idx]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
drink = []
for _ in range(N):
    drink.append(list(map(int, input().split())))
drink.sort()
ans = 0
while M > 0:
    AB = drink.pop(0)
    b = min(M, AB[1])
    ans += b * AB[0]
    M -= b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():

    N, M = map(int, input().split())
    A = []
    B = []
    total = 0
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    while M > 0:
        a = min(A)
        b = A.index(a)
        if M > B[b]:
            total += a * B[b]
            M -= B[b]
            B.remove(B[b])
            A.remove(a)
        else:
            total += a * M
            M -= M
    print(total)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

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

A_list  = []


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

A_list.sort(key=itemgetter(0))


dp = [0]*(M+1)

for i in range(1, M+1):

    for j in range(len(A_list)):
        if A_list[j][1]>0:
            A_list[j][1]-=1
            break
    
    dp[i] = dp[i-1]+A_list[j][0]

print(dp[M])

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())
  
for i in range(N):
  A.insert(2*i+1, B[i])

C = [A[i:i + 2] for i in range(0, len(A), 2)]
C.sort(key=lambda x:x[0],reverse=False)

hon = 0
kane = 0
for i in range(N):
  if C[i][1] + hon <= M:
    hon += C[i][1]
    kane += C[i][0] * C[i][1]
  else:
    kane += (M - hon) * C[i][0]
    break

print(kane)

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())
  
for i in range(N):
  A.insert(2*i+1, B[i])
 
C = [A[i:i + 2] for i in range(0, len(A), 2)]
C = sorted(C, key=lambda x:(x[0],-x[1]))
 
hon = 0
kane = 0
for i in range(N):
  if C[i][1] + hon <= M:
    hon += C[i][1]
    kane += C[i][0] * C[i][1]
  else:
    kane += (M - hon) * C[i][0]
    break
 
print(kane)

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())
  
for i in range(N):
  A.insert(2*i+1, B[i])

C = [A[i:i + 2] for i in range(0, len(A), 2)]
C = sorted(C, key=lambda x:(x[0],-x[1]))

hon = 0
kane = 0
for i in range(N):
  if C[i][1] + hon <= M:
    hon += C[i][1]
    kane += C[i][0] * C[i][1]
  else:
    kane += (M - hon) * C[i][0]
    break

print(kane)

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

n, m = list(map(int, input().split()))
shops = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    shops.append((a, b))

shops = sorted(shops, key=itemgetter(0))
drink = [[a] * b for (a, b) in shops]
drink = sum(drink, [])
# print(drink)
answer = sum(drink[:m])
print(answer)

Submission status: Time Limit Exceeded

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

total = 0
while len(A) > 0:
    i = A.index(min(A))
    if B[i] == M:
        total += A[i] * B[i]
        break
    elif B[i] > M:
        total += A[i] * M
        break
    else:
        total += A[i] * B[i]
        M -= B[i]
        A.pop(i)
        B.pop(i)
print(total)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

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

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

cnt = 0
ans = 0

while cnt != m:
    for i in range(len(dataSorted)):
        if dataSorted[i][1] != 0:
            cnt += 1
            ans += dataSorted[i][0]
            dataSorted[i][1] -=1
            break
        else:
            continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst = [[int(s) for s in input().split()]] + lst
lst.sort()
count=0
cost=0
for e in lst:
  count+=e[1]
  cost+=e[0]*e[1]
  if(count>=M):
    cost-=e[0]*(count-M)
    break
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst=lst+[[int(s) for s in input().split()]]
lst.sort()
count=0
cost=0
for e in lst:
  count+=e[1]
  cost+=e[0]*e[1]
  if(count>=M):
    cost-=e[0]*(count-M)
    break
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst=lst+[[int(s) for s in input().split()]]
lst.sort()
n=0
cost=0
for i in range(N):
  n+=lst[i][1]
  cost+=lst[i][0]*lst[i][1]
  if(n>=M):
    break
if(n>M):
  cost-=lst[i][0]*(n-M)
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
pre_lst=[]
for i in range(N):
  a,b = [int(s) for s in input().split()]
  pre_lst=pre_lst+[[a,b,a*b]]
lst = sorted(pre_lst, key=lambda x: x[0])
m=0
i=0
cost=0
while m<M:
  m+=lst[i][1]
  cost+=lst[i][2]
  i+=1
if(m>M):
  cost-=lst[i-1][0]*(m-M)
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
pre_lst=[]
for i in range(N):
  a,b = [int(s) for s in input().split()]
  pre_lst=pre_lst+[[a,b,a*b]]
lst = sorted(pre_lst, key=lambda x: x[0])
m=0
i=0
cost=0
while(m<M):
  m+=lst[i][1]
  cost+=lst[i][2]
  i+=1
if(m>M):
  cost-=lst[i-1][0]*(m-M)
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  a,b = [int(s) for s in input().split()]
  lst=lst+[[a,b,a*b]]
lst.sort()
m=0
i=0
cost=0
while(m<M):
  m+=lst[i][1]
  cost+=lst[i][2]
  i+=1
if(m>M):
  cost-=lst[i-1][0]*(m-M)
print(cost)

Submission status: Time Limit Exceeded

Solution code:
N,M = [int(s) for s in input().split()]
lst=[]
for i in range(N):
  lst=lst+[[int(s) for s in input().split()]]
lst.sort()
n=0
i=0
cost=0
while(n<M):
  n+=lst[i][1]
  cost+=lst[i][0]*lst[i][1]
  i+=1
if(n>M):
  cost-=lst[i-1][0]*(n-M)
print(cost)

Submission status: Time Limit Exceeded

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

a, b = map(int, input().split())

A.append(a)
B.append(b)

if N != 1:
    for n in range(N-1):
        a, b = map(int, input().split())
        swi = 0
        for j in range(len(A)):
            if A[j] > a:
                A.insert(j, a)
                B.insert(j, b)
                swi = 1
                break
        if swi == 0:
            A.append(a)
            B.append(b)

cntSum = 0
moneySum = 0

for n in range(N):
    if cntSum + B[n] > M:
        moneySum += A[n] * (M - cntSum)
        cntSum += M - cntSum
        break
    else:
        cntSum += B[n]
        moneySum += A[n] * B[n]

print(moneySum)

Submission status: Time Limit Exceeded

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

li.sort()

li3 = []
for j in range(len(li)):
    li3.extend([li[j][0]]*li[j][1])

print(sum(li3[0:M]))

Submission status: Time Limit Exceeded

Solution code:
N,M = (map(int, input().split()))
li = list((input().split()) for i in range(N))
for x in range(len(li)):
    li[x] = [int(i) for i in li[x]]
 
li.sort()
#print(li)
li2=[]
#for i in range(len(li)):
#    li2.append(li[i][0]*li[i][1])
#print(li2)
li3 = []
for j in range(len(li)):
    for i in range(li[j][1]):
        li3.append(li[j][0])
#print(li3)
print(sum(li3[0:M]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
c=0
g=0
for i in range(n):
  a[i], b[i] = map(int, input().split())
while c<m:
  j=a.index(min(a))
  if c+b[j]<m:
    g+=a[j]*b[j]
    c+=b[j]
  elif c+b[j]>=m:
    g+=a[j]*(m-c)
    c=m
  a.pop(j)
  b.pop(j)
print(g)

Submission status: Time Limit Exceeded

Solution code:
inp = input().split()
n = int(inp[0])
m = int(inp[1])

arr_a = []
arr_b = []
for i in range(n):
    tmp = [int(x) for x in input().split()]
    arr_a.append(tmp[0])
    arr_b.append(tmp[1])

soukei = 0
kosuu = 0
for i in range(n):
    nedan_tmp = min(arr_a)
    min_ind = arr_a.index(nedan_tmp)
    kau_tmp = arr_b[min_ind]
    if kosuu + kau_tmp > m:
        soukei = soukei + nedan_tmp * (m-kosuu)
        break
    else:
        soukei = soukei + nedan_tmp * kau_tmp
        kosuu = kosuu + kau_tmp
        del arr_a[min_ind]
        del arr_b[min_ind]



print(soukei)

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
a = [int(i) for i in a]
drink_nume = []
drink_price = []

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

count = 0

while (a[1] > 0):
    min_index = drink_price.index(min(drink_price))
    if drink_nume[min_index] > a[1]:
        count += drink_price[min_index] * a[1]
        a[1] = 0
    else:
        count += drink_price[min_index] * drink_nume[min_index]
        a[1] -= drink_nume[min_index]
    drink_nume.pop(min_index)
    drink_price.pop(min_index)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    k, l = list(map(int, input().split()))
    a.append(k)
    b.append(l)
sum = 0
money = 0
index = a.index(min(a))
while sum + b[index]< m:
    sum += b[index]
    money += a[index] * b[index]
    del a[index]
    del b[index]
    index = a.index(min(a))
money += (m - sum) * a[index]
print(money)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import sys

def input():
    return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
price = [a[i][0] for i in range(N)]
stock = [a[i][1] for i in range(N)]
min_num = 0
min_place = 0
bought = 0
total_price = 0

for i in range(N):
    min_num = min(price)
    min_place = price.index(min_num)
    if bought + stock[min_place] <= M:
        total_price += stock[min_place] * min_num
        bought += stock[min_place]
    else:
        total_price += (M - bought) * min_num
        break
    stock.pop(min_place)
    price.pop(min_place)
print(total_price)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import sys

def input():
    return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
price = [a[i][0] for i in range(N)]
min_num = 0
min_place = 0
bought = 0
total_price = 0

for i in range(N):
    min_num = min(price)
    min_place = price.index(min_num)
    if bought + a[min_place][1] <= M:
        total_price += a[min_place][0] * a[min_place][1]
        bought += a[min_place][1]
    else:
        total_price += (M - bought) * a[min_place][0]
        break
    a.pop(min_place)
    price.pop(min_place)
print(total_price)

Submission status: Time Limit Exceeded

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

li.sort()

li2=[]
for i in range(len(li)):
    li2.append(li[i][0]*li[i][1])

li3 = []
for j in range(len(li)):
    for i in range(li[j][1]):
        li3.append(li[j][0])

print(sum(li3[0:M]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
 
ab = [[int(x) for x in input().split()] for _ in range(n)]
 
ab.sort(key=lambda x: x[0])
 
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]
 
count, cost, index = 0, 0, 0

for bottle in b:
  if count + bottle < m:  
    count += bottle
    cost += a[index] * bottle
    index += 1
  else:
    cost += a[index] * (m - count)
    break

print(cost)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

ab.sort(key=lambda x: x[0])

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

ab.sort(key=lambda x: x[0])

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder


total += sum([a[i] * b[i] for i in range(index)])


print(total)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(l[0]), int(l[1])] for l in (input().split() for i in range(n))]
ab.sort()
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder


total += sum([a[i] * b[i] for i in range(index)])


print(total)

Submission status: Time Limit Exceeded

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

ab = [[int(l[0]), int(l[1])] for l in (input().split() for i in range(n))]
ab.sort()
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder
# print(a[index])
# print(remainder)
# print(total)

total += sum([a[i] * b[i] for i in range(index)])


print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m  =map(int,input().split())
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
mon = 0
lm.sort(key = lambda x:x[0])
 
while s + lm[0][1] < m:
    s += lm[0][1]
    mon += lm[0][1]*lm[0][0]
    lm = lm[1::]
if s +lm[0][1] >= m:
    mon += lm[0][0]*(m-s)
    
print(mon)

Submission status: Time Limit Exceeded

Solution code:
n,m  =map(int,input().split())
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
mon = 0
lm.sort(key = lambda x:x[0])

while s + lm[0][1] < m:
    s += lm[0][1]
    mon += lm[0][1]*lm[0][0]
    lm = lm[1::]
while s < m:
    s += 1
    mon += lm[0][0]
    lm[0][1] -= 1
    
print(mon)

Submission status: Time Limit Exceeded

Solution code:
n,m  =map(int,input().split())
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
mon = 0
lm.sort(key = lambda x:x[0])
while s < m:
    s += 1
    mon += lm[0][0]
    lm[0][1] -= 1
    if lm[0][1] == 0:
        lm = lm[1::]
print(mon)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]

nl = []
for i in range(N):
    for j in range(l[i][1]):
        nl.append(l[i][0])
    
sorted_nl = sorted(nl)

ans = 0
for i in range(M):
    ans += sorted_nl[i]
    
print(ans)

Submission status: Time Limit Exceeded

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

nl = []
for i in range(N):
    for j in range(l[i][1]):
        nl.append(l[i][0])
    
sorted_nl = sorted(nl)

ans = 0
for i in range(M):
    ans += sorted_nl[i]
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
a = []
for i in range(N):
    array = list(map(int,input().split()))
    a.append(array)
a.sort()
ans = 0
bought = 0
while bought!=M:
    b=a.pop(0)
    if bought+b[1]>M:
        ans+= b[0]*(M-bought)
        bought=M
        print(ans)
        exit()
    ans += b[0]*b[1]
    bought += b[1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
d=defaultdict(int)
N,M=map(int,input().split())
ans=0
t=M
for i in range(N):
	a,b=map(int,input().split())
	d[a]+=b
while t>0:
	for i in range(d[min(d)]):
		ans+=min(d)
		t-=1
		if t==0:break
	d.pop(min(d))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a=[]
b=[]
sum=0
for i in range(n):
  aa,bb=map(int,input().split())
  a.append(aa)
  b.append(bb)
while True:
  s=min(a)
  t=a.index(s)
  sum += s*b[t]
  m -= b[t]
  if m<=0:
    sum += s*m
    break
  del a[t],b[t]
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
i=0
x=[]
while i!=n:
    a=list(map(int,input().split()))
    x.append(a)
    i=i+1
x.sort()
m_now=0
n_now=0
while m!=m_now:
    a=x[0]
    del x[0]
    if m>=m_now+a[1]:
        m_now=m_now+a[1]
        n_now=n_now+a[0]*a[1]
    else:
        while m!=m_now:
            m_now=m_now+1
            n_now=n_now+a[0]
print(n_now)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

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)
    


#N 店の軒数


#M 買いたい本数
#A 一本の価格
#B 買える本数
yen = 0

while True:
    i = A.index(min(A))
    y = min(A)
    #print(A,B,i,y)
    if B[i] >= M:
        yen += M*A[i]
        break
    else:#B[i] < M
        yen += B[i] * A[i]
        M -= B[i]
        del B[i]
        del A[i]
        
print(yen)

Submission status: Time Limit Exceeded

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

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

values.sort()

count = 0
ans = 0

for i in range(len(values)):
  if count < M:
    count +=1
    ans += values[i]
  else:
    break



print(ans)

Submission status: Time Limit Exceeded

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

a_ = np.empty(0, dtype=int)
b_ = np.empty(0, dtype=int)
for i in range(n):
    a, b = np.array(list(map(int, input().split())))
    a_ = np.append(a_, a)
    b_ = np.append(b_, b)

arg = np.argsort(a_)
i = 0
res = 0
for j in arg.tolist():
    res += a_[j] * b_[j]
    i += b_[j]
    if i >= m:
        res -= a_[j] * (i - m)
        break

print(res)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
AB=list(list(map(int,input().split())) for _ in range(N))
AB.sort(key=lambda x:x[0])
cost=0
for ab in AB:
    for i in range(ab[1]):
        if M>0:
            M-=1
            cost+=ab[0]
print(cost)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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())

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        if len(C) < M:
            C.append(min(A))
        else:
            break
    B.pop(A.index(min(A)))
    A.remove(min(A))

C = sorted(C)
print(sum(C[:M]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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())

C = deque()

while len(C) < M:
    for j in range(B[A.index(min(A))]):
        C.append(min(A))
    B.pop(A.index(min(A)))
    A.remove(min(A))

C = sorted(C)
print(sum(C[:M]))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
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())

C = deque()

for i in range(N):
    for j in range(B[i]):
        C.append(A[i])

C = sorted(C)
print(sum(C[:M]))