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:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort()
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
        print(ans)
        break

Submission status: Accepted

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

ab.sort()
cnt = 0
ans = 0
for i in range(n):
	ans += ab[i][0] * min(ab[i][1], m - cnt)
	cnt += min(ab[i][1], m - cnt)
	if cnt == m:
		print(ans)
		exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split(" "))
    prices = []
    for i in range(N):
        tmp = list(map(int, input().split(" ")))
        prices.append(tuple(tmp))
    prices.sort(key=lambda x: x[0])
    cost = 0
    for price in prices:
        if M < 0:
            break
        cost += price[0] * min(M, price[1])
        M = max(0, M - price[1])
    print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

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()
buy_num=0
i=0
ans=0

for i in range(N):

    ai=AB[i][0]
    bi=AB[i][1]
    
    if M-buy_num>bi:
        buy_num+=bi
        ans+=ai*bi
            
    else:
        #bu_num+=M-ans
        ans+=ai*(M-buy_num)
        break
        
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

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

# (x,y)みたいな構造体をN個まとめてリストにするとき
A = []
for i in range(N):
    a = tuple(map(int, input().split()))
    A.append(a)

A = sorted(A)

index = 0
ans = 0
while M>0:
    if M >= A[index][1]:
        ans += A[index][0]*A[index][1]
        M -= A[index][1]
    else:
        ans += A[index][0]*M
        M = 0
    index += 1

print(ans)

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 x: x[0])
now_item = 0
money = 0

for e in AB:
    price = e[0]
    amount = e[1]
    if now_item + amount < M:
        now_item += amount
        money += price * amount
    else:
        money += price * (M - now_item)
        print(money)
        exit()

Submission status: Accepted

Solution code:
import sys


N, M = map(int, input().split())
S = [list(map(int, x.split())) for x in sys.stdin.readlines()]

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

amount = 0

for a, b in S:
    num = min(M, b)
    amount += a * num
    M -= num
    if M == 0:
        break

print(amount)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
 
def main():
    N, M = map(int, readline().split())
    d = map(int, read().split())
    AB = list(zip(d, d))
    AB = sorted(AB)
 
    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break
 
        else:
            price += x * y
            have += y
 
 
    print(price)
 
main()

Submission status: Accepted

Solution code:
import sys

n, m, *ab = map(int, sys.stdin.read().split())
ab = sorted(zip(*[iter(ab)] * 2))

def main():
    cost = 0
    r = m
    for a, b in ab:
        if b <= r:
            cost += a * b
            r -= b
        else:
            cost += a * r
            break
    return cost

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
price_num = [[int(i) for i in input().split()] for _ in range(N)]
price_num = sorted(price_num, key=lambda x: x[0])

rest_necessary_num = M
necessary_money = 0
for pn in price_num:
    price, num = pn
    if rest_necessary_num >= num:
        # 安いところ買い切り
        necessary_money += price * num
        rest_necessary_num -= num
    else:
        # 残り必要な分だけ買う
        necessary_money += price * rest_necessary_num
        break

print(necessary_money)

Submission status: Accepted

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

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

Submission status: Accepted

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



def main():
    N, M = map(int, readline().split())
    d = map(int, read().split())
    AB = list(zip(d, d))
    AB = sorted(AB)

    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.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
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()

Submission status: Accepted

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
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break

        else:
            price += x * y
            have += y


    print(price)

main()

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

num = 0
val = 0
for ab in AB:
    if num+ab[1] >= M:
        val += (M-num)*ab[0]
        break
    else:
        val += ab[1]*ab[0]
        num += ab[1]
print(val)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
acc = 0
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))
for a,b in sorted(ab):
    c = min(b,m)
    m -= c
    acc += a * c    
    if m == 0:
        break
print(acc)

Submission status: Accepted

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]))
c = 0
mony = 0
for i in a:
    if c + i[1] < m:
        c += i[1]
        mony += i[0]*i[1]
    else:
        for j in range(i[1]):
            c += 1
            mony += i[0]
            if c >= m:
                break
        break
print(mony)

Submission status: Accepted

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

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

stores = sorted(stores)
drinks = 0
price = 0
for s in stores:
    drinks += s[1]
    price += s[0] * s[1] 
    if drinks == M:
        break
    elif drinks > M:
        price -= (drinks - M) * s[0]
        break
        
print(price)

Submission status: Accepted

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

li.sort()

ans = 0
for i in range(n):
    a = min(m,li[i][1])
    m -= a
    ans += li[i][0]*a
    if a == 0:
        break
print(ans)

Submission status: Accepted

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

nw = 0
cst = 0
for i in range(n):
    memo = min(m,li[i][1])
    m-=memo
    cst += li[i][0]*memo
    if m==0:
        break
print(cst)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [[int(i) for i in input().split()]for j in range(N)]
sortsecond = lambda val: val[0]
AB.sort(key=sortsecond)
ans = 0
c = 0
for ab in AB:
    if c+ab[1] <= M:
        ans += (ab[0] *ab[1])
        c += ab[1]
        continue
    else:
        while c != M:
            c += 1
            ans += ab[0] 
        break

print(ans)

Submission status: Accepted

Solution code:
# ABC121C - Energy Drink Collector
def main():
    N, M, *AB = map(int, open(0).read().split())
    AB = list(zip(*[iter(AB)] * 2))
    AB.sort()
    ans = 0
    for a, b in AB:
        while b > 0 and M > 0:
            ans += a
            b -= 1
            M -= 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m = na()
ab = []
for _ in range(n):
    abi = na()
    ab.append(abi)

ab.sort()
ai, bi = ab[0][0], ab[0][1]
c = 0
ans = 0
while m > 0:
    bi -= 1
    ans += ai
    m -= 1
    if bi == 0 and m != 0:
        c += 1
        ai, bi = ab[c][0], ab[c][1]

print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    l=[list(map(int,input().split())) for _ in range(N)]
    l.sort()
    c=0
    ans=0
    for i in range(N):
        if c>M:
            break
        ans+=min(M-c,l[i][1])*l[i][0]
        c+=l[i][1]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]#[～円,～本]
AB=sorted(AB,key=lambda x:x[0])


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

Submission status: Accepted

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

def main():
    N, M = [int(x) for x in input().split()]
    ab = []
    for _ in range(N):
        ab.append([int(x) for x in input().split()])
    ab.sort()

    ans = 0
    for a, b in ab:
        if b > M:
            ans += a * M
            break
        else:
            ans += a * b
            M -= b

    print(ans)


    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ablista = []
for y in range(n):
    ab = tuple(map(int,input().split()))
    ablista.append(ab)
ablista.sort()    
k = 0
c = 0
for x in ablista:
    if k+x[1] <m:
        c = c+ x[0]*x[1]
        k = k + x[1]
       
    else:
        c = c+(m-k)*x[0]
        
        break
print (c)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
li=[]
for i in range(n):
    a,b=map(int,input().split())
    li.append((a,b))
li.sort()
pp=0
cj=0
while m>0:
    cj+= min(li[pp][1],m)*li[pp][0]
    m-=min(li[pp][1],m)
    pp+=1
print(cj)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

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

sum = 0
for i in range(len(L)):
    l = L[i]
    if l[1]<M:
        M = M - l[1]
        sum = sum + l[0]*l[1]
    else:
        sum = sum + l[0]*M
        print(sum)
        sys.exit()      

print(sum)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
B=sorted(A)
cnt=0
m=0
for i in range(N):
  if B[i][1]>=M-cnt:
    m+=(M-cnt)*B[i][0]
    print(m)
    exit()
  else:
    cnt+=B[i][1]
    m+=B[i][0]*B[i][1]

Submission status: Accepted

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

ans=0
for i in range(n):
    if ab[i][1]<=m:
        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=map(int,input().split())
s=[list(map(int,input().split())) for i in range(N)]
s=sorted(s,key=lambda x:x[0])

ans=0
cnt=0
for i in range(N):
    cnt+=s[i][1]
    if M >= cnt:
        ans+=s[i][0]*s[i][1]
    elif M < cnt:
        cnt-=s[i][1]
        ans+=(M-cnt)*s[i][0]
        break
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

(shop_count, require) = [int(i) for i in input().rstrip().split(" ")]
shop_list = sorted([[int(i) for i in input().rstrip().split(" ")] for j in range(shop_count)])

ans = 0
count = 0
for i in shop_list:
    if count + i[1] >= require:
        ans += i[0] * (require - count)
        break
    else:
        ans += i[0] * i[1]
        count += i[1]

print(ans)

Submission status: Accepted

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

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

shop = 0
cost = 0
bought = 0

while bought < m:
    price = data[shop][0]
    stock = data[shop][1]

    if m - bought <= stock:
        buy = m - bought
    else:
        buy = stock

    cost += price * buy
    bought += buy
    shop += 1

print(cost)

Submission status: Accepted

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

count=0

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

print(count)

Submission status: Accepted

Solution code:
def main():
	n,m = map(int,input().split())
	# n,k = map(int,input().split())
	# n = str(input())
	# a = list(map(int,input().split()))
	# rsp = list(str(input()))
	l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	# print(l)
	l_s = sorted(l)
	# print(len(l))

	ans_yen = 0
	ans_can = 0
	stock = 0
	i = 0
	while m > ans_can and i <= int(len(l_s))-1:
		while stock < l_s[i][1] and m > ans_can:
			# print("shop {} 's turn".format(i))
			ans_yen += l_s[i][0]
			stock += 1
			ans_can += 1
			# print("--¥ {}--".format(ans_yen))
			# print("--ans_can is {}--".format(ans_can))
		# print("i is {}".format(i))
		stock = 0
		i += 1
		# print("ans_can is {}".format(ans_can))
		# ans_can += 1
	print(ans_yen)


 
if __name__ == '__main__':
	main()

Submission status: Accepted

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

a.sort()
now = m
ans = 0
for i in range(n):
    ans += a[i][0] * min(now,a[i][1])
    now -= a[i][1]
    if now <= 0:
        break
print(ans)

Submission status: Accepted

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


from operator import itemgetter
def main():
    AB.sort(key = itemgetter(0))
    cnt = 0
    ans = 0
    for a,b in AB:
        if b + cnt < m:
            cnt += b 
            ans += b*a
        else:
            ans += (m - cnt)*a
            print(ans)
            return



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n_store, n_drink = [int(i) for i in input().split()]
stores = [[int(i) for i in input().split()] for _ in range(n_store)]  # price, n_stock
stores.sort(key=lambda x: x[0], reverse=True)  # priceでソート

ans = 0
while n_drink:
    store = stores.pop()
    price, n_stock = store

    n_buy = min(n_stock, n_drink)  # stockがなくなるかn_drinkに到達するまで買う
    ans += n_buy * price
    n_drink -= n_buy
print(ans)

Submission status: Accepted

Solution code:
n_store, n_drink = [int(i) for i in input().split()]
stores = [[int(i) for i in input().split()] for _ in range(n_store)]  # price, n_stock
stores.sort(key=lambda x: x[0], reverse=True)  # priceでソート

ans = 0
while True:
    if n_drink == 0:
        # n_drinkが0になったら終了
        break
    store = stores.pop()
    price, n_stock = store

    n_buy = min(n_stock, n_drink)  # stockがなくなるかn_drinkに到達するまで買う
    ans += n_buy * price
    n_drink -= n_buy
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a = [list(map(int,input().split())) for l in range(N)]
a.sort()
cost=0
for i in range(N):
    if M<=a[i][1]:
        cost+=a[i][0]*M
        break
    elif M>a[i][1]:
        M-=a[i][1]
        cost+=a[i][0]*a[i][1]
print(cost)

Submission status: Accepted

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

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

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

print(c)

Submission status: Accepted

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

ls_ab.sort()
ans = 0
kosu = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

AB = sorted(AB)


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

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
a = sorted(tuple(map(int,input().split())) for i in range(n))
ans = 0
for x in a:
  temp = min(x[1],k)
  ans += temp*x[0]
  k = max(0,k-temp)
print(ans)

Submission status: Accepted

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


ans = 0
k.sort()
for i in range(n):
    ml = min(k[i][1],m)
    ans += k[i][0] * ml
    m -= k[i][1]
    if m <= 0:
        break
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for a, b in AB:
    k = min(b, M)
    ans += k * a
    M -= k
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li = []
for _ in range(n):
    a, b = map(int, input().split())
    li.append((a, b))
li.sort()
money = 0
for a, b in li:
    if m <= 0: break
    if b > m:
        money += a * m
    else:
        money += a * b
    m -= b
print(money)

Submission status: Accepted

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

n, k = map(int, input().split())
arr = list(tuple(map(int, input().split())) for _ in range(n))
arr = sorted(arr, key=lambda x:x[0])
res = 0
for i in range(n):
    tk = min(k, arr[i][1])
    res += tk*arr[i][0]
    k -= tk
print(res)

Submission status: Accepted

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

n,m=map(int,readline().split())
d = map(int,read().split())
data = list(zip(d,d))
data.sort(key=lambda x:x[0])
c=0
cost=0
for x,y in data:
  if m-c<=y:
    cost+=(m-c)*x
    break
  else:
    c+=y
    cost+=y*x
print(cost)

Submission status: Accepted

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

l.sort()

drink_cnt = 0
ans = 0
for cost, cnt in l:
    if drink_cnt + cnt <= m:
        ans += cost * cnt
        drink_cnt += cnt
        if drink_cnt == m:
            break
    else:
        ans += cost * (m - drink_cnt)
        break

print(ans)

Submission status: Accepted

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 = zip(A, B)
C = sorted(C)
A, B = zip(*C)

total_price = 0
total_num = 0
for i in range(n):
    if total_num < m:
        buy = min(B[i], m - total_num)
        total_num += buy
        total_price += buy*A[i]
    else:
        break
print(total_price)

Submission status: Accepted

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

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

con = 0
yen = 0

flag = 0

for i in range(N):
  amount = AB[i][1]
  price = AB[i][0]
  for j in range(0,amount):
    con += 1
    yen += price
    if con == M:
      flag = 1
      break
  if flag == 1:
    break
    
print(yen)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
 
ABs.sort()
 
ans = 0
for A, B in ABs:
    ans += A * min(M, B)
    M -= min(M, B)
print(ans)

Submission status: Accepted

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

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

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

money=0
bottle=M
for a in AB:
    if bottle>=a[1]:
        money+=a[0]*a[1]
        bottle-=a[1]
    else:
        money+=a[0]*bottle
        bottle-=bottle
        break
print(money)

Submission status: Accepted

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

ab.sort()

ans = 0
c = 0
for a, b in ab:
  if c + b >= m:
    ans += (m - c) * a
    break
  else:
    ans += a * b
    c += b
print(ans)

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, M = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

AB.sort()
AB = np.array(AB, dtype=int)
cs = AB[:, 1].cumsum()
i = np.searchsorted(cs, M, side='left')
ans = (AB[:i, 0] * AB[:i, 1]).sum()
ans += (M - AB[:i, 1].sum()) * AB[i, 0]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
AB = AB[np.argsort(AB[:, 0])]

cnt = 0
sum_A = 0
for a, b in AB:
    sum_A += a * b
    cnt += b
    if cnt > M:
        ans = sum_A - (cnt - M) * a
        break
else:
    ans = sum_A

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
E = 0
i = 0
C = 0
while E < M:
  if E + A[i][1] > M:
    C += (M - E) * A[i][0]
    E = M
  else:
    E += A[i][1]
    C += A[i][0] * A[i][1]
    i += 1
print(C)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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])
cnt = 0
cost = 0

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

ans = cost
print(ans)

Submission status: Accepted

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])
num = M
idx = 0
ans = 0
while num != 0:
    n = min(num, A[idx][1])
    ans += n * A[idx][0]
    num -= n
    idx += 1

print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter


def solve():
    N, M = map(int, input().split())
    AB = [[0, 0] for _ in range(N)]
    for i in range(N):
        AB[i][0], AB[i][1] = map(int, input().split())

    AB.sort(key=itemgetter(0))

    ans, cnt = 0, 0
    for i in range(N):
        if M <= cnt + AB[i][1]:
            ans += AB[i][0] * (M - cnt)
            break
        else:
            ans += AB[i][0] * AB[i][1]
            cnt += AB[i][1]
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, AB: "List[[int, int]]"):
    AB = sorted(AB)
    ans = 0
    bought_drink = 0
    for ab in AB:
        if M - bought_drink > ab[1]:
            ans += ab[0] * ab[1]
            bought_drink += ab[1]
        else:
            ans += ab[0] * (M - bought_drink)
            bought_drink = M
            break
    print(ans)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, M = map(int, input().split())
    AB = []
    for n in range(N):
        AB.append(list(map(int, input().split())))
    solve(N, M, AB)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
ans=0
n,m=map(int,input().split())
lst=[0]*n
zan=m
for i in range(n):
    a,b=map(int,input().split())
    lst[i]=[a,b]
lst.sort(key=lambda x: x[0])

for i in range(n):
    if lst[i][1]<=zan:
        zan-=lst[i][1]
        ans+=lst[i][1]*lst[i][0]
    elif lst[i][1]>zan:
        ans+=lst[i][0]*zan
        break
print(ans)

Submission status: Accepted

Solution code:
n, need = map(int, input().split())
a = sorted(tuple(map(int, input().split())) for _ in range(n))
spent = 0
for price, count in a:
    buy = min(count, need)
    spent += buy * price
    need -= buy
    if need == 0:
        break
print(spent)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
N, M = map(int, input().split())

queue = []

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

count = 0
ans = 0

while count < M:
  a, b = heappop(queue)
  
  if count + b < M:
    count += b
    ans += a * b
  else:
    c = (M - count)
    count += c
    ans += c * a
  
print(ans)

Submission status: Accepted

Solution code:
from operator import itemgetter
n,m=map(int,input().split())
lis=[list(map(int,input().split())) for i in range(n)]
lis.sort()
s=0
for i in range(n):
  if m>lis[i][1]:
    s+=lis[i][0]*lis[i][1]
    m-=lis[i][1]
  else:
    s+=lis[i][0]*m
    break
print(s)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
ab = []
for a in range(n):
	a, b = [int(i) for i in input().split()]
	ab.append((a, b))
cnt_m = 0
sum_money = 0
while(True):
	for a, b in sorted(ab):
		buy_n = min(m - cnt_m, b)
		sum_money += buy_n * a
		cnt_m += buy_n
	if cnt_m == m:
		break
print (sum_money)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

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

stores = sorted(stores, key=lambda x: x[0])
total = 0
for (price, stock) in stores:
    total += price * min(stock, M)
    M -= stock
    if M <= 0:
        break

print(total)

Submission status: Accepted

Solution code:
N, M = [int(s) for s in input().split(' ')]
count = 0
ABs = []
for n in range(N):
    ab =  [int(s) for s in input().split(' ')]
    ABs.append(ab)
ABs.sort(key=lambda x: x[0])
m = M
yen = 0
for a, b in ABs:
    drinks = min(m, b)
    yen += drinks * a
    m -= drinks
    if m == 0:
        break
print(yen)

Submission status: Accepted

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

for i in range(n):
    a, b = list(map(int, input().split(' ')))
    aabb.append((a, b))
aabb = sorted(aabb)
ans = 0
for (a, b) in aabb:
    hoge = min(m, b)
    ans += a * hoge
    m -= hoge
    if not m:
        break
print(ans)