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:
n, m = map(int, input().split())

prices = []
numdict = {}

for _ in range(n):
  price, num = map(int, input().split())
  prices.append(price)
  numdict[price] = num

prices.sort()

result = 0
looped = 0

for mprice in prices:
  if numdict[mprice] <= (m - looped):
    result += mprice * numdict[mprice]
    looped += numdict[mprice]
  elif (m - looped) == 0:
    pass
  else:
    result += (m - looped) * mprice
    looped = m
  
print(result)

Submission status: Wrong Answer

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

ans=0

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

    L.append([a,b])

L= sorted(L)



for i in range(N):

    if M < L[i][1]:
        ans=L[i][0]*M

        print(ans)
        exit()
        
    else:


        ans = L[i][0]*L[i][1]
        M -= L[i][1]


        if M==0:

            print(ans)
            exit()


        elif M <= L[i+1][1]:

            ans += M * L[i+1][0]

            print(ans)

            exit()

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  dic[a] = b
c = sorted(dic.keys())
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)

Submission status: Wrong Answer

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

A = []
B = []
for i in AB:
    a,b = i
    A.append(a)
    B.append(b)

sortA = sorted(A)

ans = 0
num = M
for i in sortA:
    ind = A.index(i)
    k = B[ind]
    if num > k:
        num -= k
        ans += i* k
    else:
        ans += num* i
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
buffer = []
count = 0
money = 0

for i in range(N):
    buffer.append(list(map(int, input().split())))
buffer.sort()
for i in range(N):
    if(count + buffer[i][1] < M):
        count += buffer[i][1]
        money += buffer[i][0] * buffer[i][1]
    else:
        money += buffer[i][0] * (M - count)

print(money)

Submission status: Wrong Answer

Solution code:
def my_index_multi(l, x):
        return [i for i, _x in enumerate(l) if _x == x]

n, m = map(int, input().split())
sum = 0
money = 0
A = list()
B = list()
for i in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A_sorted = sorted(A)
for i in range(n):
    list_index = my_index_multi(A, A_sorted[i])
    for j in range(len(list_index)):
        index = list_index[j]
        if(B[index] >= m - sum):
            money += A[index]* (m - sum)
            sum = m
            break;
        else:
            sum += B[index]
            money += A[index]*B[index]
    if(sum == m):
        print(money)
        break

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for _ in range(N):
    a, b = map(int, input().split())
    d[a] = b
d = sorted(d.items(), key=lambda x: x[0])

ans = 0
for (a, b) in d:
    if b < M:
        ans += a * b
        M -= b
    elif b == M:
        ans += a * b
        break
    elif b > M:
        ans += a * M
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N,M = map(int, input().split())
a = []
b = []
ans = 0

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

nokori = M
for i in range(M):
    if nokori > 1:
        index = a.index(min(a))
        if nokori - (b[index]) >= 0:
            ans += a[index] * b[index]
            nokori -= b[index]
            a.pop(index)
            b.pop(index)
        else:
            ans += a[index] * nokori
            break
    else:
        break
print(ans)

Submission status: Wrong Answer

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

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

ans = 0
count = 0
while(count < M):
  min_A = np.min(A)
  min_Ai = np.argmin(A)
  B_min = B[min_Ai]
  if count + B_min > M:
    ans += min_A * (M - count)
    count = M
  else:
    ans += min_A * B_min
    count += B_min
  np.delete(A, min_Ai)
  np.delete(B, min_Ai)

print(ans)

Submission status: Wrong Answer

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

A = []
B = []
for i in AB:
    a,b = i
    A.append(a)
    B.append(b)

sortA = sorted(A)

ans = 0
num = M
for i in sortA:
    ind = A.index(i)
    k = B[ind]
    if num > k:
        num -= k
        ans += i* k
    else:
        ans += num* i
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
acsd=sorted(ab,key=lambda a:a[0])
print(n,m);print(acsd)
yen_tot=0
n_b=m
def count_p(store,n_v):
    yen,num=store
    return yen*min(n_v,num),max(n_v-num,0)
for s in acsd:
    cost,rem=count_p(s,n_b)
    yen_tot+=cost
    n_b=rem
    if rem==0: break
print(yen_tot)

Submission status: Wrong Answer

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

ab_dict = dict()
for i in range(N):
    a, b = map(int, raw_input().split())
    ab_dict[a] = b

answer = 0
for a in sorted(ab_dict.keys()):
    b = ab_dict[a]
    if M <= b:
        answer += a * M
        break
    else:
        answer += a * b
        M -= b

print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import itemgetter
N,M=(int(x) for x in input().split())
A=[]
for i in range(N):
  D=[int(x) for x in input().split()]
  A=A+[D]
print(A)    
result=A.sort(key=itemgetter(0))
print(A)
count=M
sum=0
for i in range(N):
  if count-A[i][1]>0:
    count=count-A[i][1]
    sum=sum+A[i][0]*A[i][1]
  else:
    sum=sum+count*A[i][0]
    break
print(sum)

Submission status: Wrong Answer

Solution code:
class Shop():
    def __init__(self, a, b):
        self.a = a
        self.b = b

N, M = [ int(x) for x in input().split(' ')]
shops = []
for i in range(N):
    a, b = [int(x) for x in input().split(' ')]
    shops.append(Shop(a, b))

shops.sort(key=lambda x: x.a)

cost = 0
bought = 0
for i in range(N):
    shop = shops[i]
    print(i, cost, bought, shop.a, shop.b)
    if (shop.b <= M - bought):
        cost += shop.a * shop.b
        bought += shop.b
    else:
        cost += shop.a * (M - bought)
        bought += (M - bought)
    if (bought == M):
        break

print(cost)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

shops = {}

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

shops = sorted(shops.items())
ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        print(ans)
        exit()
    else:
        ans += k[0] * k[1]
        M -= k[1]

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
d = {}
for _ in range(N):
    a, b = map(int, input().split())
    d[a] = b
d = sorted(d.items(), key=lambda x: x[0])

ans = 0
for (a, b) in d:
    if b <= M:
        ans += a * b
        M -= b
    else:
        ans += a * M
        break
print(ans)

Submission status: Wrong Answer

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

A = [x[0] for x in a]
B = [x[1] for x in a]
A_sorted = sorted(A)
ans = 0
nokori = M
for c in A_sorted:
	for j in range(N):
		if c == A[j]:
			ans += A[j]*min(B[j],nokori)
			nokori -= B[j]
		if nokori <= 0:
			print(ans)
			exit()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
AB = {}
for n in range(N):
    a, b = list(int(x) for x in input().split())
    AB[a] = b
yen = 0
AB = sorted(AB.items())
for a, b in AB:
    if b <= M:
        yen += a*b
        M -= b
    else:
        yen += a*M
print(yen)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = defaultdict(int)
array = []
for i in range(a):
    x, y = map(int, input().split())
    d[x] = y
    array.append(x)
array.sort()


count = 0
for i in array:
    if b <= d[i]:
        count += min(b, 0) * i
        break
    else:
        t = d[i]
        b -= t
        count += t * i
print(count)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

shops = {}

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

shops = sorted(shops.items())
print(shops)
ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        print(ans)
        exit()
    else:
        ans += k[0] * k[1]
        M -= k[1]

Submission status: Wrong Answer

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

for i in range(N):

    A[i],B[i] = map(int,input().split())
    C[i] = [A[i],B[i]]

C.sort()

while a == 0:

    if check + C[k][1] <= M:

        check += C[k][1]
        money += C[k][0]*C[k][1]

        if check + C[k][1] < M:

            k += 1

    else:

        money += C[k][0] * (M-check)
        a += 1

print(money)

Submission status: Wrong Answer

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

ab = [0]*N

for i in range(N):
    ab[i]=input().rstrip().split()

ab = sorted(ab)

sum = 0
sum_money = 0
for i in range(N):
    if sum + int(ab[i][1]) < M:
        sum += int(ab[i][1] )
        sum_money += int(ab[i][1])*int(ab[i][0])
    else:
        while(sum!=M):
            sum_money += int(ab[i][0])
            sum += 1




print(sum_money)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N, M = map(int, raw_input().split())

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:
    if count == M: break

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count

print yen

Submission status: Wrong Answer

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

A = [x[0] for x in a]
B = [x[1] for x in a]
print(B)
print(A)
A_sorted = sorted(A)
print(A_sorted)
ans = 0
nokori = M
for c in A_sorted:
	print(c)
	for j in range(N):
		if c == A[j]:
			print(j)
			ans += A[j]*min(B[j],nokori)
			nokori -= B[j]
		if nokori <= 0:
			print(ans)
			exit()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
t = [tuple(map(int, input().split())) for i in range(N)] 
t = sorted(t, key = lambda tt: tt[1])
n = 0
ans = 0
for a,b in t:
    if n+b < M:
        ans += a*b
        n += b
    else:
        ans += (M-n)*a
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())  # 複数数値入力

A = [[0, 0]] * N
for i in range(N):
    A[i] = list(map(int, input().split()))  # 複数数値入力

A = np.array(A, dtype=np.float64)
A = A[np.argsort(A[:, 0])]

ans = 0
for i in range(N):
    if M >= A[i][1]:
        M -= A[i][1]
        ans += A[i][0] * A[i][1]
        print(M)
    else:
        ans += A[i][0] * M
        break

print(int(ans))

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = defaultdict(int)
array = []
for i in range(a):
    x, y = map(int, input().split())
    d[x] = y
    array.append(x)
array.sort()


count = 0
for i in array:
    if b <= d[i]:
        count += b * i
        break
    else:
        t = d[i]
        b -= t
        count += t * i
print(count)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

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

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


# i　何軒めの店まで見ているか，何本買うか
# dp[i][j]

# dp = [[10**10 for i in range(m)] for j in range(n)]

shops.sort()
ans = 0
count = m
# print(shops)
i = 0
while True:
    print(count,ans)
    yen,num = shops[i]
    if count-num > 0:
        count -= num
        ans += yen*num
        # print(ans)
        i += 1
    else:
        ans += yen*count
        # print(ans)
        count -= count
        break


print(ans)

Submission status: Wrong Answer

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

A = []
B = []
for i in AB:
    a,b = i
    A.append(a)
    B.append(b)

sortA = sorted(A)

ans = 0
num = M
for i in sortA:
    ind = A.index(i)
    k = B[ind]
    if num > k:
        num -= k
        ans += i* k
    else:
        while True:
            if num == 0:
                break
            ans += i
            num -=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
c={}
d=[]
for i in range(n):
  a,b=map(int,input().split())
  if a not in c:
    c[a]=0
  c[a]+=b
  d.append(a)
  
d.sort()

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

Submission status: Wrong Answer

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

ab.sort()
print(ab)
ans = 0
for i in range(N):
    if M <= ab[i][1]:
        ans += (M * ab[i][0])
        break
    else:
        ans += (ab[i][0] * ab[i][1])
        M -= ab[i][1]

print(ans)

Submission status: Wrong Answer

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

ab_dict = dict()
a_set = set()
for i in range(N):
    a, b = map(int, raw_input().split())
    a_set.add(a)
    ab_dict[a] = b

answer = 0
for a in sorted(a_set):
    b = ab_dict[a]
    if M <= b:
        answer += a * M
        break
    else:
        answer += a * b
        M -= b

print(answer)

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = defaultdict(int)
array = []
for i in range(a):
    x, y = map(int, input().split())
    d[x] = y
    array.append(x)
array.sort()


count = 0
for i in array:
    if b <= 0:
        break
    if b <= d[i]:
        count += b * i
        break
    else:
        t = d[i]
        b -= t
        count += t * i
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N, M = map(int, raw_input().split())

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:
    if count > M: break

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count

print yen

Submission status: Wrong Answer

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

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

A = [list(map(int, input().split())) for i in range(N)]
A = sorted(dict(A).items())

ans = 0
m = M
for a, b in A:
    if m <= b:
        ans += m*a
        break
    else:
        ans += b*a
        m -= b

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N, M = map(int,input().split())
shops = []
for i in range(N):
  shops.append(list(map(int,input().split())))
shops.sort(key=itemgetter(1))
daikin = 0
can = 0
j = 0
while can < M:
  daikin += (shops[j][0]*shops[j][1])
  can += shops[j][1]
  j += 1
if can > M:
  daikin -= (can - M)*shops[j-1][0]
print(daikin)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

n, m = map(int, input().split())
store = [] 
cart, price = 0, 0

for _ in range(n):
    temporary_dict = {}
    a, b = map(int, input().split())
    temporary_dict["value"] = a
    temporary_dict["stock"] = b
    store.append(temporary_dict)

store.sort(key=itemgetter("value", "stock"))

for i in range(n):
    test_value = store[i]["value"]
    test_stock = store[i]["stock"]
    if test_stock < m:
        m -= test_stock
        price += test_value*test_stock
    else:
        price += test_value*m

print(price)

Submission status: Wrong Answer

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

AB.sort(key = lambda x:x[0])
A = []
B = []
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])

ans = 0
for i in range(N):
    if M - A[i]>0:
        ans += A[i]*B[i]
        M -= B[i]
    else:
        while M > 0:
            ans += A[i]
            M -= 1

print(ans)

Submission status: Wrong Answer

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

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

sorted_shop = sorted(shop, key=lambda x: x[1])

count = m
money = 0
for shop in sorted_shop:
	if count == 0:
		break
	if count >= shop[1]:
		count = count - shop[1]
		money += shop[0] * shop[1]
	else:
		money += shop[0] * count
		count = 0

print(money)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

shops = {}

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

shops = sorted(shops.items())

ans = 0

for k in shops:
    if M - k[1] <= 0:
        ans += k[0] * M
        print(ans)
        exit()
    else:
        ans += k[0] * k[1]
        M -= k[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.zeros(N, dtype=np.int)
B = np.zeros(N, dtype=np.int)

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

all_sum = B.sum()

arg_sorted = np.argsort(A)

sum_amount = 0
sum_money = 0
to_break = False
# print(M)
for i in arg_sorted:
    if A[i] > M-sum_amount:
        to_break = True
    lot = min(B[i], M-sum_amount)

    sum_money += A[i]*lot
    sum_amount += lot
    # print(i, A[i], sum_amount, sum_money)

    if to_break:
        break


print(sum_money)

Submission status: Wrong Answer

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

data.sort()
num = 0
for x in data:
    for xx in range(int(x[1])):
        M -= 1
        num += int(x[0])
        if(M == 0):
            break
    if(M == 0):
        break
print(num)

Submission status: Wrong Answer

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)
C = A.copy()
A.sort()
cnt = 0
for i in range(N):
    if M==0:
        break
    num = B[C.index(A[i])]
    if M >= num:
        M -= num
        cnt += num * A[i]
    else:
         cnt += M * A[i]
         break
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

shops = {}

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

shops = sorted(shops.items())

ans = 0

for k in shops:
    if M - k[1] < 0:
        ans += k[0] * M
        print(ans)
        exit()
    else:
        ans += k[0] * k[1]
        M -= k[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.zeros(N, dtype=np.int)
B = np.zeros(N, dtype=np.int)

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

all_sum = B.sum()

arg_sorted = np.argsort(A)

sum_amount = 0
sum_money = 0
to_break = False
print(M)
for i in arg_sorted:
    if A[i] > M-sum_amount:
        to_break = True
    lot = min(B[i], M-sum_amount)

    sum_money += A[i]*lot
    sum_amount += lot
    print(i, A[i], sum_amount, sum_money)

    if to_break:
        break


print(sum_money)

Submission status: Wrong Answer

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

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

rl = [i for i in reversed(l)]
by = rl[0:M]
print (sum(by))

Submission status: Wrong Answer

Solution code:
s = input().split()
N = int(s[0])
M = int(s[1])

AB = [input() for i in range(N)]
AB.sort()
money = 0
num = 0
for data in AB:
  data = data.split()
  A = int(data[0])
  B = int(data[1])
  if num+B < M:
    money += A*B
  elif num+B == M:
    money += A*B
    break
  else:
    money += A*(M-num)
    break
  num += B
print(money)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
li={}
for i in range(N):
	a,b = map(int,input().split())
	li[a]=b
li=sorted(li.items())
m_sum=0
for k,v in li:
	if M==0:
		break
	elif v <=M:
		M-=v
		m_sum+=k*v
	else:
		m_sum+=k*M
		M=0
print(m_sum)

Submission status: Wrong Answer

Solution code:
N,M=map(int, raw_input().split())
e_list=[]
result=0
m=M

for i in range(N):
    e_list.append(map(int, raw_input().split()))

e_list.sort()

#print N,M,e_list

for i in range(N):
    cost=e_list[i][0]
    mnum=e_list[i][1]
    if m == 0:
        print result
        break
    elif m >= mnum:
        result = result + cost * mnum
        m = m - mnum
    elif m < mnum:
        result = result + cost * m
        m = 0

Submission status: Wrong Answer

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

ans=0

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

    L.append([a,b])

L= sorted(L)



for i in range(N):

    ans = L[i][0]*L[i][1]
    M -= L[i][1]

    if M==0:

        print(ans)
        exit()


    if M <= L[i+1][1]:

        ans += M * L[i+1][0]

        print(ans)

        exit()

Submission status: Wrong Answer

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

keys = sorted(ab.keys())

ans = 0
kosu = 0
for k in keys:
    kosu += ab[k]
    if kosu >= M:
        kosu -= ab[k]
        break
    ans += k * ab[k]

for i in range(ab[k]):
    if kosu == M:
        break
    kosu += 1
    ans += k
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=[int(i) for i in input().split()]
min_money=[10000000000,1000000001,1000000002,1000000003,1000000004,1000000005,1000000006,1000000007,1000000008,1000000009]
min_buy=[0,0,0,0,0,0,0,0,0,0]
for i in range(n):
    a,b=[int(i) for i in input().split()]
    min_money.append(a)
    min_money.sort()
    min_money.pop()
    if a in min_money:
        min_buy.insert(min_money.index(a),b)
ans=0
for i in range(3):
    if min_buy[i]>=m:
        ans+=min_money[i]*m
        break
    else:
        ans+=min_money[i]*min_buy[i]
        m-=min_buy[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
tmp_lis=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
    tmp_lis.append(c)
tmp_lis.sort()
ans=0
tmp=0
flag=False
while True:
    for i in range(n):
        for j in range(n):
            if tmp_lis[i]==a[j]:
                ans+=a[j]*b[j]
                tmp+=b[j]
                if tmp>=m:
                    flag=True
                    ans-=(tmp-m)*a[j]
                break
        if flag==True:
            break
    if flag==True:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input().split()
N = int(s[0])
M = int(s[1])

AB = [input() for i in range(N)]
AB.sort()

money = 0
num = 0
for data in AB:
  data = data.split()
  if num+int(data[1]) < M:
    money += int(data[0])*int(data[1])
  else:
    money += int(data[0])*(M-num)
    break
  num += int(data[1])
print(money)

Submission status: Wrong Answer

Solution code:
import random

def quick_sort(array):
    low_array = []
    high_array = []
    if len(array) <= 1:
        return array
    pivot = random.choice(array)[0]
    pivot_count = 0
    for a in range(len(array)):
        if pivot > array[a][0]:
            low_array.append(array[a])
        elif pivot < array[a][0]:
            high_array.append(array[a])
        else:
            pivot_count += 1
    print(pivot, low_array, high_array, pivot_count)
    low_array = quick_sort(low_array)
    high_array = quick_sort(high_array)
    return low_array + [pivot, ] * pivot_count + high_array
    #return low_array + high_array

def main():
    list1=input().split(' ')
    n=int(list1[0])
    m=int(list1[1])
    biglist=[]
    for i in range(n):
        list=input().split(' ')
        biglist.append([int(list[0]), int(list[1])])
    #array = [3, 4, 2, 6, 8, 1, 7]
    array=[[5,1], [2,3], [3,4], [7,2], [6,6]]
    #new_array=quick_sort(array)
    #print(new_array)
    newlist=sorted(biglist)
    #print(sorted(biglist))
    #print(newlist, m, n)
    money=0
    jun=0
    while m>0:
        if newlist[jun][1]>=m:
            money+=m*newlist[jun][0]
            print(money)
            return
        else:
            money+=newlist[jun][0]*newlist[jun][1]
            #print(money)
            m-=newlist[jun][1]
        jun+=1

Submission status: Wrong Answer

Solution code:
N,M=(int(i) for i in input().split())
lst1=[]
lst2=[]
for i in range(N):
  a,b=(int(i) for i in input().split())
  lst1.append(a)
  lst2.append(b)
lst1copy=sorted(lst1)
num=0
ans=0
while M>0:
  A=lst1copy[num]
  n=lst1.index(A)
  if M>=lst2[n]:
    ans+=lst1[n]*lst2[n]
    M-=lst2[n]
    num+=1
  else:
    ans+=lst1[n]*M
    break
print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
print(A)
money = 0
for n in range(N):
    if m > A[n][1]:
        m -= A[n][1]
        money += A[n][1] * A[n][0]
    elif m <= A[n][1]:
        money += m * A[n][0]
        break

print(money)

Submission status: Wrong Answer

Solution code:
NM = list(map(int,input().strip().split()))
N = NM[0]
M = NM[1]
ABs = []
for i in range(0,N):
    AB =list(map(int,input().strip().split()))
    ABs.append(AB)

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

ene_num = 0
cost = 0
for ab in ABs:
    nums = min(ab[1], M)
    cost += ab[0] * nums
    M -= nums
    if M - nums == 0:
        break


print(cost)

Submission status: Wrong Answer

Solution code:
N,M=[int(z) for z in input().split(" ")]
d={}

for z in range(0,N):
  buf=[int(z) for z in input().split(" ")]
  d[buf[0]]=buf[1]

r=M
ans=0
for z in sorted(d.items()):

  if r==0:
    break
  if z[1]<=r:
     ans+=z[0]*z[1]
     r-=z[1]
  else:
    ans+=z[0]*r
    r=0

print(ans)

Submission status: Wrong Answer

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

for _ in range(n):
    aa,bb=map(int,input().split())
    ab.append((aa,bb))

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

ans=0
sums=0

for c in ab:
    sums+=min(c[1],m)
    ans+=min(c[1],m)*c[0]

    if sums>=m:
        print(ans)
        exit()
    m-=c[1]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

AB = sorted(AB)

count = 0
result = 0
i = 0
while M != count:
    if 0 < int(AB[i][1]):
        result += int(AB[i][0])
        count += 1
        AB[i][1] = int(AB[i][1]) - 1
    else:
        i += 1
print(result)

Submission status: Wrong Answer

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

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

l.reverse()
by = l[0:M]
print (sum(by))

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.readline


def readln():
    return list(map(int, read().split()))


N, M = readln()

data = {}
for _ in range(N):
    a, b = readln()
    data[a] = b

ans = 0
drink = 0
for k, v in sorted(data.items()):
    ans += k * v
    drink += v
    if drink > M:
        break
print(ans-k*(drink-M))

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(n)]
AB.sort(reverse = True)
c = 0
ans = 0
i = 0
while c < m:
  if  c + AB[i][1] <= m:
    c += AB[i][1]
    ans += AB[i][0]*AB[i][1]
    i += 1
  else:
    ans += AB[i][0]*(m-c)
    break

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 = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]

A = []
B = []
D = {}
for i in range(N):
    A.append(AB[i][0])
    B.append(AB[i][1])

for i in range(N):
    D[A[i]] = B[i]

L = list(D.keys())
L.sort()
ans = 0
for i in L:
    if M - D[i] > 0:
        ans += i*D[i]
        M -= D[i]
    else:
        while M > 0:
            ans += i
            M -= 1

print(ans)

Submission status: Wrong Answer

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

L.sort()

tmp = 0
num = 0
for i in range(N):
    if num +  L[i][1] <= M:
        tmp += L[i][0] * L[i][1]
        num += L[i][1] 
    else:
        tmp += (M - num) * L[i][0]
        num = M
        
    if tmp == M:
        break


print(tmp)

Submission status: Wrong Answer

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

for i in range(0, N):
    A, B = [int(i) for i in input().split()]
    shops.append((A, B))

shops.sort()

print(shops)
result = 0
rest_count = M
for shop in shops:
    if rest_count > shop[1]:
        result += shop[0] * shop[1]
        rest_count -= shop[1]
    else:
        result += shop[0] * rest_count
        break

print(result)