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

Solution code:
import numpy as np

n, m = map(int, input().split())
ab = np.zeros((n, 2))
for i in range(n):
    a_tmp, b_tmp = map(int, input().split())
    ab[i, 0] = a_tmp
    ab[i, 1] = b_tmp

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

cnt = 0
yen = 0
for i in range(n):
    if m - cnt >= ab[i][1]:
        cnt += ab[i][1]
        yen += ab[i][0] * ab[i][1]
    else:
        yen += (m - cnt) * ab[i][0]
        cnt += m - cnt

        break

print(int(yen))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a =[]
b =[]
for i in range(n):
    x1, y1 = [int(i) for i in input().split()]
    a.append(x1)
    b.append(y1)

c = zip(a, b)
c=sorted(c)
a, b = zip(*c)
a=list(a)
b=list(b)

d = 0
money = 0
for i in range(n):
    if d == m:
        break
    else:
        if m-d <= b[i]:
            num = m-d
            d += num
            money += num*a[i]
        else:
            num = b[i]
            d += num
            money += num*a[i]

    #print(d,money)

print(money)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
l = [list(map(int,input().split())) for _ in range(n)]
cnt = 0
ans = 0
l.sort(key=lambda x:x[0])
for i in range(n):
    cnt += l[i][1]
    ans += l[i][0] * l[i][1]
    if cnt > m:
        ans -= l[i][0] * l[i][1]
        ans += l[i][0]*(m-(cnt-l[i][1]))
        break
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
dat_d = []
for i in range(n):
    a,b = map(int, input().split())
    dat_d.append((a, b))
dat_d.sort(key=lambda x: x[0])
total = 0
for i in range(m):
    if dat_d[i][1] >= m:
        #print("buy {0} sum {1}-hon".format(dat_d[i][0], m))
        total += dat_d[i][0] * m
        break
    else:
        #print("buy {0} sum {1}-hon".format(dat_d[i][0], dat_d[i][1]))
        total += dat_d[i][1] * dat_d[i][0]
        m -= dat_d[i][1]

print(total)

Submission status: Accepted

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

a_list = []
b_list = []

for i in range(n):
    a,b = input().split()
    a_list.append(int(a))
    b_list.append(int(b))


price_order = sorted(range(len(a_list)), key=lambda k: a_list[k])

m_carrent = m
sum_price = 0
for p in price_order:
    if m_carrent - b_list[p] >=0:
        sum_price += b_list[p] * a_list[p]
    else:
        sum_price += m_carrent * a_list[p]
        break

    m_carrent -= b_list[p]

print(sum_price)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[0])
ans = 0
cur = 0
for i in range(n):
  if cur+ab[i][1]<m:
    ans += ab[i][0]*ab[i][1]
    cur += ab[i][1]
  else:
    ans += (m-cur)*ab[i][0]
    break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A=[]
total=0
money=0
point=-1
over=0
for i in range(N):
    A.append(list(map(int, input().split())))

A.sort()

while(total<M):
    point +=1
    money+=A[point][0]*A[point][1]
    total +=A[point][1]

over=total-M
money -= over*A[point][0]

print(money)

Submission status: Accepted

Solution code:
#a, b, c, d = (int(i) for i in input().split())  
#W = [int(i) for i in input().split()] 
# N= (int(input()))

N, M = (int(i) for i in input().split())  
flag = 0
A_list = []
B_list = []
AB_list = []
for i in range(N):
    a,b= (int(j) for j in input().split())  
    A_list.append(a)
    B_list.append(b)
    AB_list.append([a,b])
    pass
AB_list = sorted(AB_list, key=lambda x: x[0])
#print(AB_list)
now = 0
m_cnt = 0
n_cnt = 0
for ab in AB_list:
    #print(n_cnt + (ab[1]))
    if n_cnt + ab[1] >= M:
        a = M - n_cnt
        n_cnt += a
        m_cnt += (a * ab[0])
        break
    else:
        n_cnt += ab[1]
        m_cnt += (ab[1] * ab[0])
        pass

print(m_cnt)
# k_list = []
# s_list = []
# p_list = []
# for i in range(M):
#     for j in range(N):
#         a = [int(i) for i in input().split()] 
#         k_list.append(a[0])
#         s_list.append(a[1:])
#         pass
#     pass
# p_list = [int(i) for i in input().split()] 

# lamp_list = []



# #N = int(input())
# # A = [int(i) for i in input().split()] 
# #S_dict = {}
# #P_dict = {}
# # for i in range(N):
# #     tmp = input()
# #     S = tmp.split()[0]
# #     P = int(tmp.split()[1])
# #     if S in S_dict.keys() and P < S_dict[S]:
# #         pass
# #     else:
# #         S_dict[S] = P
# #         pass
# #     pass
# # S_dict = sorted(S_dict.items())

# # print(type(S_dict))
# # name_lisy = []

# # for k in S_dict:
# #     name_lisy.append(k)
# #     pass
# # print(name_lisy)
# S_list = []
# P_list = []
# for i in range(N):
#     tmp = input()
#     S = tmp.split()[0]
#     P = int(tmp.split()[1])
#     #print(S,P)
#     S_list.append([S,P])
#     #P_list.append(P)
#     pass
# #S_list.sort()
# #print(S_list)
# sorted_S_list = sorted(S_list, key=lambda x:x[1], reverse=True)
# sorted_S_list = sorted(sorted_S_list, key=lambda x:x[0])
# #print(sorted_S_list)

# for i,k in enumerate(sorted_S_list):
#     for j,l in enumerate(S_list):
#         if sorted_S_list[i] == S_list[j]:
#             print(j+1)
#             break
#         pass
#     pass


# #print(P_list)

# for i in range(M):
#     # A.sort()
#     if min(A) < C_list[i]:
#         for j in range(B_list[i]):        
#             if min(A) < C_list[i]:
#                 A.append(C_list[i])
#                 pass
#             pass
#         A.sort(reverse=True)
#         A = A[:N]
#         pass
#     pass
# #sum(A[:N-1])
# print(sum(A[:N]))
# for i in range(M):
#     A.sort()
#     cnt = 0
#     for j in range(N):
#         if cnt < B_list[i] and A[j] < C_list[i]:
#             A[j] = C_list[i]
#             cnt += 1
#             pass
#         pass
#     #print(A)
#     pass
# print(sum(A))






# L_max = max(L_list)
# R_min = min(R_list)
# for i in range(M):
#     pass

# if R_min-L_max+1 < 0:
#     print("0")
# else:
    
#     print(R_min-L_max+1)
# if A <= 5:
#     print(0)
# elif 5 < A and A <= 12:
#     print(int(B/2))
# else:
#     print(B)

Submission status: Accepted

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
drink = {}
for i in range(0, N):
    a, b = [int(x) for x in stdin.readline().rstrip().split()]
    if not a in drink:
        drink[a] = 0
    drink[a] += b

cost = 0
buy_drinks = 0
for price, num in sorted(drink.items()):
    if buy_drinks + num > M:
        cost += (M-buy_drinks) * price
        buy_drinks = M
        break
    else:
        cost += price * num
        buy_drinks += num

print(cost)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lst = []
for i in range(N):
	a, b = map(int, input().split())
	lst.append([a, b])
	
lst = sorted(lst, key = lambda x : x[0])
money = 0
bottle = 0
flg = 0
for elm in lst:
	if flg == 1:
		break
	if bottle + elm[1] < M:
		money += elm[0] * elm[1]
		bottle += elm[1]
	else:
		for i in range(elm[1]):
			money += elm[0]
			bottle += 1
			if bottle >= M:
				flg = 1
				break
print(money)

Submission status: Accepted

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

sl = sorted(l)
buy = 0
ans = 0
for i in range(N):
    for j in range(sl[i][1]):
        if buy < M:
            ans += sl[i][0]
            buy += 1
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
shop = []
for _ in range(N):
  A = list(int(i) for i in input().split())
  shop.append(A)
shoplist = sorted(shop)
t = 0
k = 0
while k < M:
  k += shoplist[t][1]
  t += 1
x = 0
for i in range(t):
  x += shoplist[i][0]*shoplist[i][1]
print(x-(k-M)*shoplist[t-1][0])

Submission status: Accepted

Solution code:
import heapq

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

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

cnt = 0
ans = 0
while True:
    a, b = heapq.heappop(shops)
    if cnt + b >= m:
        ans += a * (m - cnt)
        cnt += m - cnt
        break
    else:
        ans += a * b
        cnt += b

print(ans)

Submission status: Accepted

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
for i in range(N):
    if bought+a[i][1]>M:
        ans+= a[i][0]*(M-bought)
        bought=M
        print(ans)
        exit()
    ans += a[i][0]*a[i][1]
    bought += a[i][1]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

AB.sort()

cnt = 0
yen = 0

for a,b in AB:
  if cnt + b <= M:
    cnt += b
    yen += a * b
    continue
  yen += a * (M - cnt)
  break

answer = yen
print(answer)

Submission status: Accepted

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

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

for i in range(N):
    buy = min(M, shop[i][1])
    ans += buy * shop[i][0]
    M -= buy
    if M == 0:
        print(ans)
        exit()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
edr=[]
for i in range(n):
  edr.append(list(map(int,input().split())))
edr.sort(key =lambda x:x[0])
cnt=0
ans=0
for i in range(n):
  cnt+=edr[i][1]
  ans+=edr[i][0]*edr[i][1]
  if cnt>=m:
    ans-=(cnt-m)*edr[i][0]
    break
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls.sort(key=lambda x: x[0])
drink = 0
ans = 0
for i in range(n):
    if drink + ls[i][1] < m:
        ans += ls[i][0]*ls[i][1]
        drink += ls[i][1]
    else:
        ans += ls[i][0]*(m-drink)
        print(ans)
        break

Submission status: Accepted

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

li = sorted(li,key = lambda x : x[0])
drink = 0
ans = 0
for i in range(n):
  if drink + li[i][1] < m:
    ans += li[i][0]*li[i][1]
    drink += li[i][1]
  else:
    ans += li[i][0]*(m - drink)
    print(ans)
    exit()

Submission status: Accepted

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

shop_list = [0] * N

for n in range(N):
    shop_list[n] = list(map(int, input().split()))

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

need_count = M
cost = 0
for item in sorted_list:
    if need_count >= item[1]:
        cost += item[1] * item[0]
        need_count -= item[1]
        if need_count < 0:
            break
    elif need_count < item[1]:
        cost += need_count * item[0]
        need_count -= item[1]
        if need_count < 0:
            break
print(cost)

Submission status: Accepted

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

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

total=0
ans=0
for price,num in drinks:
    if total+num<M:
        total+=num
        ans+=price*num
    else:
        ans+=price*(M-total)
        break

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
l = [[0]*2 for i in range(n)]
for i in range(n):
    l[i][0], l[i][1] = map(int, input().split())
l = sorted(l)
price = 0

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

print(price)

Submission status: Accepted

Solution code:
N,m=map(int,input().split())
L=sorted([list(map(int,input().split())) for _ in range(N)])
ans=0
for i in range(N):
	ans+=L[i][0]*min(m,L[i][1])
	m-=min(m,L[i][1])
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(0,n):
    b,c=map(int,input().split())
    a.append([b,c])
a.sort()
number=0
for i in range(0,len(a)):
    if number<m:
        number=number+a[i][1]
        l=i
answer=0
kosu=0
for k in range(0,l):
    answer=answer+a[k][0]*a[k][1]
    kosu=kosu+a[k][1]
answer=answer+a[l][0]*(m-kosu)
print(answer)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = [[int(_) for _ in input().split()] for i in range(N)]
AB.sort(key = lambda x:x[0])
cost = 0
got = 0
index = 0
s = 0
while got < M:
    got += AB[index][1]
    index += 1
g = got - AB[index-1][1]

plus = M - g

for i in range(index-1):
    cost += AB[i][0] * AB[i][1]
    

cost += plus * AB[index-1][0]    
    
print(cost)

Submission status: Accepted

Solution code:
n1, n2 = [int(i) for i in input().split()]

n3 = []

for i1 in range(n1):
    n3.append([int(j) for j in input().split()])

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

r1 = 0
for i2 in range(n1):
    if n2 > n3[i2][1]:
        r1 += n3[i2][0] * n3[i2][1]
        n2 -= n3[i2][1]
    else:
        r1 += n3[i2][0] * n2
        break

print(r1)

Submission status: Accepted

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

X = []
cost = []
stock = []

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

X.sort()
price, stock = zip(*X)

accumulated = []
accumulated.append(0)

for i in range(n):
  accumulated.append(accumulated[i] + stock[i])

bought = 0
cost = 0
i = 0

while bought + stock[i] < m:
  bought += stock[i]
  cost += price[i] * stock[i]
  i += 1

print(cost + (m - accumulated[i]) * price[i])

Submission status: Accepted

Solution code:
from operator import itemgetter
N,M=map(int,input().split())
AB=[]
for i in range(N):
    ABtmp=list(map(int,input().split()))
    AB.append(ABtmp)
    
AB.sort(reverse=False,key=itemgetter(0))

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

print(ans)

Submission status: Accepted

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


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

list = sorted(list)

quantity = 0
ans = 0

while quantity < m:
    value = list.pop(0)
    ans,quantity = ans+(value[0]*value[1]),quantity+value[1]

if quantity > m:
    temp = quantity-m
    ans = ans-temp*value[0]

print(ans)

Submission status: Accepted

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

for a,b in AB:
    if M >= b:
        money += a*b
        M -= b
    else:
        money += a*M
        break
print(money)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(tuple(map(int,input().split())))
a.sort()
count=0
for i in range(n):
  m-=a[i][1]
  count+=a[i][0]*a[i][1]
  if m<=0:
    count+=a[i][0]*m
    print(count)
    break

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = []
count = 0
money = 0
k = 0
for i in range(n):
    a,b = map(int,input().split())
    l.append((a,b))
l.sort(key=lambda x:x[0])
while count < m:
    money = money + (l[k][0])*(l[k][1])
    count = count + l[k][1]
    k = k + 1
money = money - (count - m)*l[k-1][0]
print(money)

Submission status: Accepted

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

ab.sort()

i=0
ans = 0
while m>0:
    if ab[i][1]>m:
        ans += m*ab[i][0]
        break
    else:
        ans += ab[i][1]*ab[i][0]
        m-=ab[i][1]
        i+=1

print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,m = get_nums_l()
lines = sys.stdin.readlines()

shops = [None] * n
for i,line in enumerate(lines):
    shops[i] = tuple(map(int, line.split(" ")))

shops.sort(key=lambda s:s[0])

ans = 0
i = 0
count = 0
while count < m:
    nokori = max(0, m - count)
    kau = min(nokori, shops[i][1])
    count += kau
    ans += kau * shops[i][0]
    i += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
ab = []
ans = 0
for i in range(n):
    _a,_b = map(int,input().split())
    ab.append([_a,_b])
sab = sorted(ab)
for i in range(n):
    num = sab[i][1]
    if num <= m:
        m -= num
        ans += sab[i][0]*sab[i][1]
    else:
        ans += sab[i][0]*m
        m = 0
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
# 入力
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N)))

# 1本あたりの値段が安い店から順に購入
ans, _ = reduce(
    lambda acc, t:
        (
            acc[0] + t[0] * min(t[1], M - acc[1]),
            acc[1] + t[1]
        ) if acc[1] < M else
        acc,
    sorted(zip(A, B)),
    (0, 0)
)

# 出力
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, stderr, setrecursionlimit, exit
setrecursionlimit(2147483647)
def getint():
    return int(stdin.readline().rstrip('\r\n'))
def getints():
    return [int(i) for i in stdin.readline().rstrip('\r\n').split()]
def getintlines():
    return [int(i) for i in stdin.readlines()]
def getintslines():
    return [[int(i) for i in s.split()] for s in stdin.readlines()]
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n, m = getints()
shops = getintslines()

shops.sort(key=lambda x:x[0])
current_drink = 0
current_money = 0
for price, num in shops:
    current_money += price * num if current_drink + num <= m else price * (m - current_drink)
    current_drink += num
    if current_drink >= m:
        break
    
print(current_money)

Submission status: Accepted

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

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

m = 0
c = 0
for a,b in sorted(xs,key=lambda x:x[0]):
    if m+b <= M:
        m+=b
        c+=a*b
    else:
        #print('b', M-m)
        c+=a*(M-m)
        m+=M-m
        break
print(c)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
ans=0
for i in range(n):
    a.append(list(map(int,input().split())))
a=sorted(a)
for i in range(n):
    m=m-a[i][1]
    if(m<=0):
        ans+=a[i][0]*(a[i][1]+m)
        break
    else:
        ans+=a[i][1]*a[i][0]
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(N)])
res = 0
for a,b in AB:
    M -= b
    res += a*b
    if M < 0:
        res += a*M
        break
print(res)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [0]*N
for n in range(N):
    AB[n] = list(map(int, input().split()))
    
AB.sort(key = lambda x:x[0])

bottle = 0
cost = 0

for n in range(N):
    if AB[n][1] + bottle < M:
        bottle += AB[n][1]
        cost += AB[n][0] * AB[n][1]
    else:
        cost += AB[n][0] * (M-bottle)
        break

print(cost)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[[int(i)for i in input().split()]for _ in range(n)]
ab.sort()
c=0
x=0
for i in range(n):
  m-=ab[i][1]
  c+=1
  if m<=0:
    x-=m
    break
p=0
for i in range(c):
  p+=ab[i][0]*ab[i][1]
print(p-ab[c-1][0]*x)

Submission status: Accepted

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

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

total_amount = 0
total_price = 0
for price,amount in ab:
    bought = min(amount,M-total_amount)
    total_amount += bought
    total_price += price * bought

print(total_price)

Submission status: Accepted

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

res = M
total = 0
for i in range(N):
  if(res > AB[i][1]):
    newbuy = AB[i][1]
  else:
    newbuy = res
  total += newbuy*AB[i][0]
  res = res - newbuy

print(total)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ab = []
for n in range(N):
    a,b = map(int,input().split())
    ab.append((a,b))
ab.sort()
coin = 0
cnt = 0
for n in range(N):
    cnt += ab[n][1]
    coin += ab[n][1] * ab[n][0]
    if cnt >= M:
        coin -= (cnt - M) * ab[n][0]
        print(coin)
        exit()

Submission status: Accepted

Solution code:

N,M = input().split()
N = int(N)
M = int(M)
ans = 0

AB = []

for i in range(N):

    A,B = input().split()
    AB.append([int(A),int(B)])

AB.sort()

for i in range(N):

    if (AB[i][1] < M):

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

    else:
        ans += AB[i][0] * M
        break

print (ans)

Submission status: Accepted

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

while M>0:
    ans+=AB[n][0]*AB[n][1]
    M-=AB[n][1]
    if M<0:
        ans+=M*AB[n][0]
    n+=1
    
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = list(list(map(int,input().split()))for i in range(N))
AB.sort()
ans = 0
i = 0
while M > 0:
    A,B = AB[i]
    ans += A*B
    M -= B
    i+=1
ans += M*A
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = list(list(map(int,input().split()))for i in range(N))
AB.sort()
ans = 0
while M > 0:
    A,B = AB.pop(0)
    ans += A*B
    M -= B
ans += M*A
print(ans)

Submission status: Accepted

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:
        n_now=n_now+a[0]*(m-m_now)
        m_now=m
print(n_now)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()

  l=[]
  for _ in range(n):
    a,b=LI()
    l.append([a,b])

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

  sm=0
  for x in l:
    if m>x[1]:
      m-=x[1]
      sm+=x[0]*x[1]
    else:
      sm+=x[0]*m
      return sm

print(main())

Submission status: Accepted

Solution code:
def resolve():
    (N, M) = list(map(int, input().split(" ")))
    ABs = [list(map(int, input().split(" "))) for i in range(N)]
    sortedABs = sorted(ABs, key=lambda x: x[0])
    cost = 0
    num = 0
    for ab in sortedABs:
        if ab[1] < M-num:
            num = num + ab[1]
            cost = cost + ab[0]*ab[1]
        else:
            cost = cost + ab[0]*(M-num)
            break
    print(cost)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import heapq
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, M = map(int, input().split())
A, B = [0] * N, [0] * N
C = []

for i in range(N):
	A[i], B[i] = map(int, input().split())
	heapq.heappush(C, (A[i], B[i]))
	
ans = 0

for i in range(M):
	tmp = heapq.heappop(C)
	ans += tmp[0]
	if tmp[1] > 1:
		heapq.heappush(C, (tmp[0], tmp[1] - 1))

print(ans)

Submission status: Accepted

Solution code:
nm, left = map(int, input().split())
shops = []
for _ in range(nm):
    shops.append([int(x) for x in input().split()])
shops.sort(key=lambda x: x[0])
#print(shops)
total_cost = 0
for cost, stock in shops:
    if stock >= left:
        print(total_cost + cost * left)
        exit(0)
    else:
        left = left - stock
        total_cost += cost * stock
        #print("current : " + str(total_cost))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [[0,0] for _ in range(n)]
for i in range(n):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
    ans += l[i][0]*min(m,l[i][1])
    m -= min(m,l[i][1])
    if m == 0:
        break
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
c = sorted(c)
cost = 0
for i in range(n):
    if(m==0):
        break
    else:
        if(c[i][1]>m):
            cost+=(m*c[i][0])
            m = 0
        else:
            cost+=(c[i][1]*c[i][0])
            m-=c[i][1]
print(cost)

Submission status: Accepted

Solution code:
def resolve():
	N,M=map(int,input().split())
	L=[]
	for i in range(N):
		a,b=map(int,input().split())
		L.append([a,b])
	D=sorted(L,key=lambda x:x[0])
	ans=0
	cnt=M
	for i in D:
		if i[1]<cnt:
			ans+=i[0]*i[1]
			cnt-=i[1]
		else:
			ans+=i[0]*cnt
			break
	print(ans)
resolve()

Submission status: Accepted

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)
    
L = list(zip(A,B))
L.sort()

#N 店の軒数


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

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

Submission status: Accepted

Solution code:
num_of_drink = [int(i) for i in input().split()]
shop = [[int(i) for i in input().split()] for j in range(num_of_drink[0])]
buing_scajule = sorted(shop)
cash = 0
must_drink_num = num_of_drink[1]
i = 0

while must_drink_num != 0:
    if buing_scajule[i][1] >= must_drink_num:
        cash += buing_scajule[i][0] * must_drink_num
        must_drink_num = 0
    else:
        cash += buing_scajule[i][0] * buing_scajule[i][1]
        must_drink_num -= buing_scajule[i][1]
    i += 1

print(cash)

Submission status: Accepted

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

l = sorted(l)


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

Submission status: Accepted

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

res = 0
while m > 0:
  if l[0][1] == 0:
    l.pop(0)
  else:
    res += l[0][0]
    l[0][1] -= 1
    m -= 1
print(res)

Submission status: Accepted

Solution code:
shops, need_drink = [int(x) for x in input().split()]

price_quantity = []
for count in range(shops):
    data = [int(x) for x in input().split(" ")]
    price_quantity.append(data)

#print(price_quantity)

price_quantity.sort(key=lambda x: x[0])
bought_drink = 0
counter2 = 0
total_cost = 0
# print(price_quantity)
while bought_drink < need_drink:
    if (price_quantity[counter2][1] + bought_drink) < need_drink:
        bought_drink += price_quantity[counter2][1]
        total_cost += price_quantity[counter2][0] * price_quantity[counter2][1]
    else:
        while price_quantity[counter2][1] != 0:
            price_quantity[counter2][1] -= 1
            bought_drink += 1
            total_cost += price_quantity[counter2][0]
            if bought_drink >= need_drink:
                break
    counter2 += 1

print(total_cost)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  AB.append([int(i) for i in input().split()])

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

count = 0
ans = 0

for A,B in AB:
  if count + B > M:
    ans += A*(M-count)
    break
  else:
    ans += A*B
    count += B


print(ans)

Submission status: Accepted

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

for i in range(N) :
    a , b = map(int,input().split())
    drink[i] = [a,b] # 価格 , 本数

drink.sort(key=(lambda A : A[0])) # 安いもの順

now = 0
ans = 0

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


print(ans)

Submission status: Accepted

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

a_b = []
for i in range(n):
  a_b.append([int(i) for i in input().split()])

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

count = 0
payment = 0
for i in a_b:
  count += i[1]
  payment += i[0] * i[1]
  if count >= m:
    payment -= (count - m) * i[0]
    break

print(payment)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
store = []
cnt = 0
ans = 0
for _ in range(n) :
        a, b = map(int, input().split())
        comb = [a,b]
        store.append(comb)
store.sort()
for i in store:
        if cnt + i[1] <= m :
                ans += i[0]*i[1]
                cnt += i[1]
        else:
                ans += i[0] * (m - cnt)
                break
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
n, m = (int(i) for i in input().rstrip().split())
# print(n)
vals_list = np.zeros((n, 2))
# print(vals_list)
for itr in range(n):
    a, b = (int(i) for i in input().rstrip().split())
    vals_list[itr][0], vals_list[itr][1] = a, b
sorted_vals_list = vals_list[np.argsort(vals_list[:, 0])]
# print(sorted_vals_list)

cnt = m
total_money = 0
for itr in range(n):
    if (cnt - sorted_vals_list[itr][1]) <= 0:
        total_money += sorted_vals_list[itr][0] * cnt
        break
    else:
        cnt -= sorted_vals_list[itr][1]
        total_money += sorted_vals_list[itr][0] * sorted_vals_list[itr][1]
print(int(total_money))