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

Solution code:
from operator import itemgetter
k, b = map(int, input().split())
a=[]
from heapq import heappush, heappop
for i in range(k):
    ta,tb = map(int, input().split())
    a.append([ta,tb])
a = sorted(a, key=itemgetter(0), reverse=False)
print(a)
s=0
t = 0
ans = 0
i = 0
while s<b:
    s+=1
    if t<a[i][1]:
        ans+=a[i][0]
        t+=1
    else:
        i+=1
        ans+=a[i][0]
        t=1    

print(ans)

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
dic = {}
for i in range(N):
    
    a,b = list(map(int,input().split()))
    dic[a]=b
j = 0
s = 0
for i in sorted(dic.keys()):
    j += dic[i]
    s += dic[i] * i
    #print(" ",j,s,dic[i],M)
    if(j > M):
        print( s - i * (j-M) )
        break

Submission status: Wrong Answer

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

lis.sort()

count=0
money=0
ind=0
while count+lis[ind][1]<M:
    count+=lis[ind][1]
    money+=lis[ind][0]*lis[ind][1]
    ind+=1
    print(ind)
    

money+=(M-count)*lis[ind][0]
print(money)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = []
for i in range(n):
    pair = list(map(int,input().split()))
    l.append(pair)
else:
    l.sort()

res = 0
for i in range(n):
    m -= l[i][1]
    res += l[i][0]*l[i][1]
    if m < 0:
        res += m*l[i][0]
        print(res)
        break

Submission status: Wrong Answer

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

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)

Submission status: Wrong Answer

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

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

ans = 0
for _ in range(N):
    A.append(list(map(int,input().split())))

A = sorted(A, key=lambda x: x[0])
print(A)
for a in A:
    if a[1] >= M:
        ans += a[0]*M
        break
    else:
        ans += a[0]*a[1]
        M -= a[1]
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

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

for i in range(N):
    a, b = map(int,input().split())
    for j in range(b):
        drinks.append(a)

drinks.sort()

ans = sum(drinks[:M])

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
    l = list(map(int, input().split()))
    ll.append(l)

i = 0
while i < n-1:
    k = i+1
    while k <= n-1:
        if ll[i][0] > ll[k][0]:
            ll[i], ll[k] = ll[k], ll[i]
        k += 1
    i+=1
s = 0
cst = 0
while m > 0:
    cst += ll[s][0] * ll[s][1]
    m -= ll[s][1]
    s += 1
print(cst + m*ll[s-1][0])

Submission status: Time Limit Exceeded

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

for i in range(n):
    a, b = map(int, input().split())
    ll[i].append(a)
    ll[i].append(b)
i = 0
while i < n-1:
    k = i+1
    while k <= n-1:
        if ll[i][0] > ll[k][0]:
            ll[i], ll[k] = ll[k], ll[i]
        k += 1
    i+=1
s = 0
cst = 0
while m > 0:
    cst += ll[s][0] * ll[s][1]
    m -= ll[s][1]
    s += 1
print(cst + m*ll[s-1][0])

Submission status: Time Limit Exceeded

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


for i in range(N):
    if remain > sAB[i][1]:
        remain -= sAB[i][1]
        ans += sAB[i][0]*sAB[i][1]
    else:
        while 1:
            remain -= 1
            ans+=sAB[i][0]
        
            if remain == 0:
                break
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)
sum = 0
price = 0
while sum<M:
    x = A.index(min(A))
    sum += B[x]
    if sum >= M:
        sum -= B[x]
        break
    price += A[x]*B[x]
    del A[x]
    del B[x]

price += (M-sum)*A[x]

print(price)

Submission status: Time Limit Exceeded

Solution code:
# abc121_c.py
# https://atcoder.jp/contests/abc121/tasks/abc121_c

# C - Energy Drink Collector /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300 点

# 問題文
# 栄養ドリンクにレーティング上昇効果があると聞いた高橋くんは、M本の栄養ドリンクを買い集めることにしました。
# 栄養ドリンクが売られている店は N軒あり、i 軒目の店では 1 本 Ai 円の栄養ドリンクを Bi本まで買うことができます。
# 最小で何円あれば M本の栄養ドリンクを買い集めることができるでしょうか。
# なお、与えられる入力では、十分なお金があれば M本の栄養ドリンクを買い集められることが保証されます。

# 制約
#     入力は全て整数である。
#     1≤N,M≤105
#     1≤Ai≤109
#     1≤Bi≤105
#     B1+...+BN≥M

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N M
# A1 B1
# A2 B2
# ⋮
# AN BN

# 出力
# M本の栄養ドリンクを買い集めるのに必要な最小の金額を出力せよ。

# 入力例 1
# 2 5
# 4 9
# 2 4

# 出力例 1
# 12

# 12円あれば 1 軒目の店で 1 本、2 軒目の店で 4 本の栄養ドリンクを購入し、合計 5 本の栄養ドリンクを買い集めることができます。
# 一方、11 円以下では 5本の栄養ドリンクを買い集めることができません。

# 入力例 2
# 4 30
# 6 18
# 2 5
# 3 10
# 7 9

# 出力例 2
# 130

# 入力例 3
# 1 100000
# 1000000000 100000

# 出力例 3
# 100000000000000

# 出力が 32ビット整数型におさまらないことがあります。


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    total_cost = 0
    total_cnt = 0

    for m in range(M):
        min_a = None
        for n in range(N):
            a, b = valueses[n]
            if b > 0:
                if min_a is None:
                    min_n = n
                    min_a = a
                elif min_a > a:
                    min_n = n
                    min_a = a
        # 残り購入希望本数
        remain = M - total_cnt
        # その店ですべて購入できる場合、このループで終了
        if remain <= valueses[min_n][1]:
            return [total_cost + valueses[min_n][0]*remain]
        else:
            total_cnt += valueses[min_n][1]
            total_cost += valueses[min_n][0]*valueses[min_n][1]
            valueses[min_n][1] = 0


# 引数を取得
def get_input_lines():
    line = input()
    N, M = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 5', '4 9', '2 4']
        lines_export = [12]
    if pattern == 2:
        lines_input = ['4 30', '6 18', '2 5', '3 10', '7 9']
        lines_export = [130]
    if pattern == 3:
        lines_input = ['1 100000', '1000000000 100000']
        lines_export = [100000000000000]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

A = []
B = []
cnt = 0
ans = 0

for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


while cnt < m:
    A_min = min(A)
    A_min_index = A.index(A_min)
    if cnt + B[A_min_index] < m:
        ans += A_min * B[A_min_index]
        cnt += B[A_min_index]
        A.pop(A_min_index)
        B.pop(A_min_index)
    else:
        for i in range(B[A_min_index]):
            if cnt == m:
                break
            ans += A_min
            cnt += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def actual(N, M, AB):
    count = 0
    payment = 0

    while count < M:
        AB = [x for x in AB if x[1] > 0]
        m = min(AB, key=lambda x: x[0])

        payment += m[0]
        m[1] -= 1
        count += 1

    return payment

N, M = map(int, input().split())
AB = []
for _ in range(N):
  a, b = map(int, input().split())
  AB.append([a, b])
  
print(actual(N, M, AB))

Submission status: Time Limit Exceeded

Solution code:
from __future__ import annotations

from dataclasses import dataclass, field
from typing import List


@dataclass
class Shop:
    id: int
    price: int
    stock: int

    def buy(self) -> None:
        self.stock -= 1


@dataclass(frozen=True)
class Shops:
    values: List[Shop] = field(default_factory=list)

    def register(self, shop: Shop) -> None:
        return self.values.append(shop)

    def _bargain_shop(self) -> Shop:
        shops_have_stock = [shop for shop in self.values if shop.stock > 0]

        return sorted(shops_have_stock, key=lambda shop: shop.price)[0]

    def how_much(self, required_num: int) -> int:
        drink_count = 0
        payment = 0

        while True:
            bargain_shop = self._bargain_shop()

            bargain_shop.buy()

            payment += bargain_shop.price
            drink_count += 1

            if drink_count == required_num:
                return payment


def actual(N, M, AB):
    shops = Shops()

    for idx, (a, b) in enumerate(AB, start=1):
        shop = Shop(id=idx, price=a, stock=b)
        shops.register(shop)

    return shops.how_much(required_num=M)

N, M = map(int, input().split())
AB = []
for _ in range(N):
  a, b = map(int, input().split())
  AB.append((a,b))
  
print(actual(N, M, AB))

Submission status: Time Limit Exceeded

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

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

cost = 0
while m > 0:
    a, b = ab.pop(0)
    if b > m:
        cost += m * a
        m = 0
    else:
        cost += b * a
        m -= b
print(cost)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

D={}
for _ in range(N):
    A,B=map(int,input().split())

    if A in D:
        D[A]+=B
    else:
        D[A]=B

L=[]
for m in D:
    L.append((m,D[m]))

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

S=0
while M>0:
    (A,B)=L.pop(0)
    if B>=M:
        B=M
    S+=A*B
    M-=B
print(S)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = (int(X) for X in input().split())
Price = np.zeros((N,2),dtype=int)
for T in range(0,N):
    Price[T,:] = (np.array([int(X) for X in input().split()]))
Price = Price[np.argsort(Price[:,0])]
Drink = np.concatenate([np.full(Y,X) for X,Y in Price])[0:M]
print(sum(Drink))

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    if drink + shop[i][1] <= M:
        drink += shop[i][1]
        money += shop[i][0] * shop[i][1]
        if drink == M:
            print(money)
            break
    else:
        for j in range(shop[i][1]):
            drink += 1
            money += shop[i][0]
            if drink == M:
                print(money)
                break

Submission status: Time Limit Exceeded

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

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

for i in range(N):
    for j in range(shop[i][1]):
        drink += 1
        money += shop[i][0]
        if drink == M:
            print(money)
            break

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L=[]
for _ in range(N):
    a,b = map(int,input().split())
    L.append((a,b))
L.sort()
ans = 0
while M>0:
    a,b = L[0]
    del L[0]
    if M>=b:
        ans += a*b
    else:
        ans +=a*M
    M-=b
print(ans)

Submission status: Time Limit Exceeded

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

ans = sum(b[0:M])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n,m=map(int,input().split())

price_list=[0]*n
num_dic=defaultdict(int)

def mergesort(a):
    def _merge_sort(a, left: int, right: int):
        if left < right:
            center = (left+right)//2

            _merge_sort(a,left,center)
            _merge_sort(a,center+1,right)

            #pは前半部をbuffにコピーする際のインデックス、jで取り出す
            p=j=0
            i=k=left

            #配列の前半部をbuffにコピー
            while i <= center:
                buff[p]=a[i]
                p+=1
                i+=1

            #後半部をコピーされた前半部と比較、小さい方をaに格納していく
            while i<= right and j < p:
                if buff[j] <= a[i]:
                    a[k]=buff[j]
                    j+=1
                else:
                    a[k]=a[i]
                    i+=1
                k+=1

            while j < p:
                a[k] =buff[j]
                k+=1
                j+=1

    n=len(a)
    #merge結果を一時的に格納
    buff=[None]*n
    _merge_sort(a,0,n-1)
    del buff

for i in range(n):
    a,b=map(int,input().split())
    price_list[i]=a
    if num_dic[price_list[i]] is None:
        num_dic[price_list[i]]=b
    else:
        num_dic[price_list[i]]+=b

mergesort(price_list)
#同じ値段と違う値段で場合分け
price_sum=0
drink_count=0
for i in range(n):
    if i!=0 and price_list[i-1]==price_list[i]:
        continue
    else:
        #i番目のドリンクを買い占め
        p=price_list[i]*num_dic[price_list[i]]
        price_sum+=p
        drink_count+=num_dic[price_list[i]]
        if drink_count>=m:
            stop=i
            break

while drink_count!=m:
    drink_count-=1
    price_sum-=price_list[i]

print(price_sum)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
money=[]
for _ in range(N):
    A,B=map(int,input().split())
    for _ in range(B):
        money.append(A)
moneys=sorted(money)
print(sum(moneys[:M]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
ans=0
temp=0
for i in range(n):
  at,bt=map(int,input().split())
  a[i]=at
  b[i]=bt
import numpy as np
a=np.array(a)
b=np.array(b)
while temp<m:
  t=np.argmin(a)
  if temp+b[t]>=m:
    ans=ans+a[t]*(m-temp)
    break
  else:
    ans=ans+a[t]*b[t]
    temp=temp+b[t]
    a=np.delete(a,t)
    b=np.delete(b,t)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
ans=0
temp=0
for i in range(n):
  at,bt=map(int,input().split())
  a[i]=at
  b[i]=bt
import numpy as np
a=np.array(a)
b=np.array(b)
while temp<m:
  t=np.argmin(a)
  if temp+b[t]>=m:
    ans=ans+a[t]*(m-temp)
    break
  else:
    ans=ans+a[t]*b[t]
    temp=temp+b[t]
    a=np.delete(a,t)
    b=np.delete(b,t)
    t=np.argmin(a)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[0]*n
b=[0]*n
ans=0
temp=0
for i in range(n):
  at,bt=map(int,input().split())
  a[i]=at
  b[i]=bt
import numpy as np
a=np.array(a)
b=np.array(b)
while temp<m:
  t=np.argmin(a)
  ans=ans+a[t]
  temp=temp+1
  b[t]=b[t]-1
  if b[t]==0:
    a=np.delete(a,t)
    b=np.delete(b,t)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq

n,m = map(int,input().split(" "))
li = []
heapq.heapify(li)

for i in range(n):
    a,b = map(int,input().split(" "))
    for j in range(b):
        heapq.heappush(li,a)

result = 0
for i in range(m):
    result += heapq.heappop(li)
print(result)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in range(n)])
c=[]
for a,b in l:
    for _ in range(b):
        c.append(a)
print(sum(c[:m]))

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

flag = 1
while flag:
    flag = 0
    for j in range(n-1):
        if a[j] > a[j+1]:
            tmp = a[j]
            a[j] = a[j+1]
            a[j+1] = tmp
            res = b[j]
            b[j] = b[j+1]
            b[j+1] = res
            flag = 1

ans = 0
for i in range(n):
    if m > b[i]:
        ans += a[i]*b[i]
        m -= b[i]
    else:
        ans += m*a[i]
        break

print(ans)

Submission status: Time Limit Exceeded

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

AB.sort()

print(sum(AB[:M]))

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
N, M = map(int, input().split())
 
AB = []
 
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort(key=lambda x: x[0])
 
ans = 0
cnt = 0
whole = []
 
for ab in AB:
    for b in range(ab[1]):
        whole.append(ab[0])

ans = list(accumulate(whole))

print(ans[M-1])

Submission status: Time Limit Exceeded

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

AB = []

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

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

ans = 0
cnt = 0
whole = []

for ab in AB:
    for b in range(ab[1]):
        whole.append(ab[0])

whole = np.array(whole)
whole = whole.cumsum()

print(whole[M-1])

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
cost=[]
count=[]
ans=0
temp=0
for i in range(n):
    a,b=map(int,input().split())
    cost.append(a)
    count.append(b)
for i in range(len(cost)):
    ans+=min(cost)*count[cost.index(min(cost))]
    temp+=count[cost.index(min(cost))]
#   print("ans,temp,min(cost),min(count)=",ans,temp,min(cost),count[cost.index(min(cost))])
    if temp>=m:
        ans-=min(cost)*(temp-m)
        break
    else:
        count.remove(count[cost.index(min(cost))])
        cost.remove(min(cost))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
d = {}
for i in range(n):
  a,b = map(int,input().split())
  if a in d.keys():
    d[a] += b
  else:
    d.setdefault(a,b)
l = list(d.keys())
l.sort()
count = 0
mon = 0
i = 0
while count < m:
  mon += l[i]*d[l[i]]
  count += d[l[i]]
  i += 1
i -= 1
if count > m:
  mon -= (count-m)*l[i]
print(mon)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
d = {}
for i in range(n):
  a,b = map(int,input().split())
  if a in d.keys():
    d[a] += b
  else:
    d.setdefault(a,b)
l = list(d.keys())
l.sort()
count = 0
mon = 0
i = 0
while count < m:
  mon += l[i]*d[l[i]]
  count += d[l[i]]
  i += 1
i -= 1
if count > m:
  mon -= (count-m)*l[i]
print(mon)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
cnt = 0
ans = 0
while cnt < M:
  ind = np.argmin(A)
  m = min(M - cnt, B.pop(ind))
  ans += A.pop(ind) * m
  cnt += m
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0],x[1]))
c = 0
ans = 0
for i in range(n):
    for j in range(a[i][1]):
        if c < m:
            c += 1
            ans += a[i][0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n,m=map(int,input().split())
    drink=[]
    ans=0
    count=0
    for i in range(n):
        tmp=list(map(int,input().split()))
        drink.append(tmp)
    drink.sort()
    while(True):
        tmp=drink.pop(0)
        if m>tmp[1]:
            ans+=tmp[0]*tmp[1]
            m-=tmp[1]
        else:
            ans+=tmp[0]*m
            break
    print(ans)


resolve()

Submission status: Time Limit Exceeded

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

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

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

money = 0
cnt = 0
for i in range(N):
    for j in range(A[i][1]):
        money += A[i][0]
        cnt += 1
        if cnt == M:
            print(money)
            break

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
from sys import stdin
#import math
#from functools import reduce
    
N, M = [int(x) for x in stdin.readline().rstrip().split()]
#N = int(input())
#S = list(input())

costs = []

#is_exist = 'Yes'
for n in range(N):
    ai, bi = [int(x) for x in stdin.readline().rstrip().split()]
    costs += [ai]*bi
    
costs.sort()
#print(costs)

print(sum(costs[:M]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab=sorted(ab)
cost=[]
for i in range(n):
  cost+=[ab[i][0]]*ab[i][1]
print(sum(cost[0:m]))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
N, M = map(int,input().split())
ary1 =[]
for x in range(N):
  ary1.append(list(map(int,input().split())))

ary2 = sorted(ary1)
print(sum(reduce(lambda a,b: a+b ,[[x[0]]*x[1] for x in ary2])[0:M]))

Submission status: Time Limit Exceeded

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

ArA = [0]*n
ArB = [0]*n

for i in range(n):
	a,b = map(int, input().split())
	ArA[i] = a
	ArB[i] = b
#
j=0
mm=m
while mm>0:
#	print(j)
	mind = ArA[j]
	ind=j
	for i in range(j,n):
		if ArA[i] <= mind:
			ind=i
			mind=ArA[i]
	tmp = ArA[ind]
	ArA[ind]=ArA[j]
	ArA[j]=tmp
	tmp = ArB[ind]
	ArB[ind]=ArB[j]
	ArB[j]=tmp
	mm=mm-ArB[j]
#	print("mm=",mm)
	j=j+1
    
#print(ArA, ArB)
price = 0
i=0
while m>0:
	price = price + ArA[i] * min(m, ArB[i])
#	print(m, ArB[i],ArA[i])
	m = m - min(m, ArB[i])
	i = i+1
    
print(price)

Submission status: Time Limit Exceeded

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

ArA = [0]*n
ArB = [0]*n

for i in range(n):
	a,b = map(int, input().split())
	ArA[i] = a
	ArB[i] = b
#
for j in range(n):
	mind = ArA[j]
	ind=j
	for i in range(j,n):
		if ArA[i] <= mind:
			ind=i
			mind=ArA[i]
	tmp = ArA[ind]
	ArA[ind]=ArA[j]
	ArA[j]=tmp
	tmp = ArB[ind]
	ArB[ind]=ArB[j]
	ArB[j]=tmp
		
    
#print(ArA, ArB)
price = 0
i=0
while m>0:
	price = price + ArA[i] * min(m, ArB[i])
#	print(m, ArB[i],ArA[i])
	m = m - min(m, ArB[i])
	i = i+1
    
print(price)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,M = map(int,input().split())
shops = dict()
price = []
takahashi = 0
money = 0
for i in range(N):
    bottle,stock = map(int,input().split())
    if bottle not in shops:
        shops[bottle] = 0
    shops[bottle] += stock
    if bottle not in price:
        price.append(bottle)
price.sort()
for y in price:
    if shops[y] <= (M-takahashi):
        takahashi += shops[y]
        money += shops[y]*y
        shops[y] = 0
        if takahashi == M:
            print(money)
            sys.exit(0)
    else:
        money += y*(M-takahashi)
        takahashi += (M-takahashi)
        shops[y] -= (M-takahashi)
        if takahashi == M:
            print(money)
            sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,M = map(int,input().split())
shops = dict()
price = []
takahashi = 0
money = 0
for i in range(N):
    bottle,stock = map(int,input().split())
    if bottle not in shops:
        shops[bottle] = 0
    shops[bottle] += stock
    if bottle not in price:
        price.append(bottle)
price.sort()
for y in price:
    while takahashi != M:
        if shops[y] <= (M-takahashi):
            takahashi += shops[y]
            money += shops[y]*y
            shops[y] = 0
            break
        elif shops[y] != 0:
            takahashi += 1
            shops[y] -= 1
            money += y
        else:
            break
    if takahashi == M:
        print(money)
        sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,M = map(int,input().split())
shops = dict()
price = []
takahashi = 0
money = 0
for i in range(N):
    bottle,stock = map(int,input().split())
    if bottle not in shops:
        shops[bottle] = 0
    shops[bottle] += stock
    if bottle not in price:
        price.append(bottle)
price.sort()
for y in price:
    while takahashi != M:
        if shops[y] != 0:
            takahashi += 1
            shops[y] -= 1
            money += y
        else:
            break
    if takahashi == M:
        print(money)
        sys.exit(0)

Submission status: Time Limit Exceeded

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

S = [[0]*2 for i in range(N)]
for i in range(N):
    S[i] = list(map(int, input().split()))
     
S = sorted(S)

quantitys = 0
total = 0

for i in range(N):
    quantity = 0
    x = 0
    for ii in range(S[i][1]):
        if quantitys<M:
            quantitys += 1
            quantity += 1
    x += quantity * S[i][0]
    total += x

print(str(total))

Submission status: Time Limit Exceeded

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

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

bought = 0
ans = 0

if len(a) == 1:
    print(a[0]*m)
    exit()

while(bought <= m):
    remain = m - bought
    amin = min(a)
    bmin = b[a.index(amin)]
    if bmin <= remain:
        ans += amin*bmin
        bought += bmin
        b.remove(bmin)
        a.remove(amin)
    else:
        ans += amin*remain
        break
print(ans)

Submission status: Time Limit Exceeded

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

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

bought = 0
ans = 0

if len(a) == 1:
    print(a[0]*m)
    exit()
    
while(bought <= m):
    remain = m - bought
    if b[a.index(min(a))] <= remain:
        ans += min(a)*b[a.index(min(a))]
        bought += b[a.index(min(a))]
        b.remove(b[a.index(min(a))])
        a.remove(min(a))
    else:
        ans += min(a)*remain
        break
print(ans)

Submission status: Time Limit Exceeded

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

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

bought = 0
ans = 0
if len(a) == 1:
    print(a[0]*m)
    exit()
while(bought <= m):
    remain = m - bought
    if b[a.index(min(a))] <= remain:
        ans += min(a)*b[a.index(min(a))]
        bought += b[a.index(min(a))]
        b.remove(b[a.index(min(a))])
        a.remove(min(a))
    else:
        ans += min(a)*remain
        break
print(ans)

Submission status: Time Limit Exceeded

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

lis_A = []
lis_B = []

for _ in range(N):
    A, B = map(int, input().split())
    lis_A.append(A)
    lis_B.append(B)

cost  = 0
count  = 0

while True:
    if N == 1:
        print(lis_A[0] * lis_B[0])
        sys.exit()
    saiyasu = lis_A.index(min(lis_A))



    #ものを買う時に、Mをオーバーするなら処理
    if (lis_B[saiyasu] + count) <= M:
        cost = ((lis_B[saiyasu] * lis_A[saiyasu]) + cost)
        count  = lis_B[saiyasu] + count
        lis_A.pop(saiyasu)
        lis_B.pop(saiyasu)
    else:
        cost = (((M - count) * lis_A[saiyasu]) + cost)
        break
print(cost)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,M =[int(i) for i in input().split()]

A = np.ones(N)
B = np.ones(N)

for i in range(N):
    A[i],B[i] = [int(i) for i in input().split()]
    
count=0
price=0
for i in range(N):
    if count>=M:
        break
    min_pr = min(A)
    min_num = np.where(A==min_pr)
    min_num_count = 0
    for i in min_num[0]:
        min_num_count +=B[i]
    A = np.delete(A,min_num[0])
    B = np.delete(B,min_num[0])
    if (count+min_num_count) <=M:
        price+=min_num_count*min_pr
        count+=min_num_count
    elif (count+min_num_count) >M:
        price += (M-count)*min_pr
        count+=min_num_count

        
print(int(price))

Submission status: Time Limit Exceeded

Solution code:
N_ken, M_hon = map(int, input().split())
ab = []
yen = 0
hon = M_hon

for i in range(N_ken):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

ab.sort()

while (hon > 0):
    
    tmp = min(hon, ab[0][1])
    yen += ab[0][0] * tmp
    
    hon -= tmp
    ab.remove(min(ab))

print(yen)

Submission status: Time Limit Exceeded

Solution code:
N_ken, M_hon = map(int, input().split())
A_en = []
B_hon = []
yen = 0
hon = M_hon

for i in range(N_ken):
    a, b = map(int, input().split())
    A_en.append(a)
    B_hon.append(b)

while (hon > 0):
    index = A_en.index(min(A_en))
    tmp = min(hon, B_hon[index])
    yen += A_en[index] * tmp
    
    hon -= tmp
    A_en.remove(A_en[index])
    B_hon.remove(B_hon[index])

print(yen)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import deque

def main():
    N, M = map(int, input().split())

    AB = [0] * N
    for i in range(N):
        AB[i] = list(map(int, input().split()))

    AB = sorted(AB)

    have = 0
    price = 0
    while M != have:
        AB[0][1] -= 1
        price += AB[0][0]
        have += 1

        if AB[0][1] == 0:
            del AB[0]


    print(price)

main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ab = []
for i in range(n):
    aa, bb = map(int, input().split())
    ab.append([aa, bb])
ab.sort()

bought = 0
money = 0
while bought < m:
    for i in ab:
        if i[1] == 0:
            continue
        else:
            money += i[0]
            bought += 1
            i[1] -= 1
            break

print(money)