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
import bisect

n, m  = list(map(int, input().split()))
drinks = [list(map(int, input().split())) for _ in range(n)]

drinks.sort(key = lambda x: x[0])
prices = np.array([x[0] for x in drinks])
vols = np.array([x[1] for x in drinks])
cum_vols = np.cumsum(vols)
idx = bisect.bisect_left(cum_vols, m) #このidxは1 ~ vols[idx]を使う

#print(idx)
l = 0 if idx == 0 else sum(vols[:idx])

vols[idx] = m - l
print(np.dot(vols[:(idx+1)], prices[:(idx+1)]))

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.sort()
# print(L)
total = 0
number = 0
index = 0
while (number + L[index][1]) < M:
    number += L[index][1]
    total += L[index][0] * L[index][1]
    index += 1
    # print(number)
    # print(total)
total += L[index][0] * (M - number)
print(total)

Submission status: Accepted

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

remain = M
total_pay = 0
cur = 0
while remain > 0:
    buy = min(shop_list[cur][1], remain)
    total_pay = total_pay + shop_list[cur][0] * buy
    remain = remain - buy
    cur = cur + 1
#    print("buy:", buy, "total:", total_pay, "remain:", remain)
print(total_pay)

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 = sorted(AB, key=lambda a: a[0])
total = 0
total_count = 0
for i in range(N):
    if total_count + AB[i][1] >= M:
        total += (AB[i][0] * (M - total_count))
        break
    else:
        total_count += AB[i][1]
        total += (AB[i][0] * AB[i][1])
print(total)

Submission status: Accepted

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

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

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


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

Submission status: Accepted

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

sys.maxsize = 10000000000000000


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

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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
    if m >= 0:
        res += a*b
    else:
        m += b
        res += a*m
        break
print(res)

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-

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

c.sort()

drink = 0
price = 0

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

print(price)

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = sorted(a)
cnt = 0
money = 0
while True:
	for x,y in b:
		cnt += y
		money += x * y
		if m < cnt:
			money -= (cnt - m)*x
			print(money)
			exit()

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
  A[i], B[i] = list(map(int, input().split()))
k = list(range(N))
k.sort(key=lambda x: A[x])
r = 0
c = 0
for i in k:
  if B[i]<M-c:
    r += B[i]*A[i]
    c += B[i]
  else:
    r += (M-c)*A[i]
    c += M-c
    break
print(r)

Submission status: Accepted

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

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

ss.sort()

m = 0
for a, b in ss:
    m += a * min(b, M)
    M -= b
    if M <= 0:
        break

print(m)

Submission status: Accepted

Solution code:
import numpy as np

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

tmp_list = [[int(i) for i in input().split()] for i in range(N)]
tmp_list = np.array(tmp_list)
# print(np.argsort(tmp_list[:, 0]))
tmp_list = tmp_list[np.argsort(tmp_list[:, 0])].T
A_list = tmp_list[0]
B_list = tmp_list[1]

# print(A_list)
# print(B_list)


residue = M
min_cache = 0
idx = 0

while(True):
    if B_list[idx] >= residue:
        ans = min_cache + A_list[idx] * residue
        break
    else:
        residue = residue - B_list[idx]
        # print(residue)
        min_cache = min_cache + A_list[idx] * B_list[idx]
        # print(min_cache)
        idx += 1
    # print(min_cache)
print(ans)

Submission status: Accepted

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

AB = list(zip(A, B))
AB.sort()
A, B = zip(*AB)

sum = 0
num = 0
for i in range(N):
    num += B[i]
    if num >= M:
        num -= B[i]
        for j in range(B[i]):
            num += 1
            sum += A[i]
            if num >= M:
                print(sum)
                exit()
    else:
        sum += A[i] * B[i]

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_int(s):
    try:
        i = int(s)
    except:
        return False
    return True

ARGS_COUNT = 2
stdin = input().split()

if (len(stdin) > ARGS_COUNT):
    print("Too many arguments.")
    exit()
elif (len(stdin) < ARGS_COUNT):
    print("Too few arguments.")
    exit()
elif (not is_int(stdin[0])):
    print("N is not a number.")
    exit()
elif (not is_int(stdin[1])):
    print("M is not a number.")
    exit()

N = int(stdin[0])
M = int(stdin[1])

if (N < 1 or N > 100000):
    print("Out of range at N.")
    exit()
elif (M < 1 or M > 100000):
    print("Out of range at M.")
    exit()

A = [[] for j in range(N)]

for i in range(0, N):
    stdin = input().split()

    if (len(stdin) > ARGS_COUNT):
        print("Too many arguments.")
        exit()
    elif (len(stdin) < ARGS_COUNT):
        print("Too few arguments.")
        exit()
    elif (not is_int(stdin[0])):
        print("A[%d] is not a number." % (i + 1))
        exit()
    elif (not is_int(stdin[1])):
        print("B[%d] is not a number." % (i + 1))
        exit()
    elif(int(stdin[0]) < 1 or int(stdin[0]) > 1000000000):
        print("Out of range at A[%d]." % (i + 1))
        exit()
    elif (int(stdin[1]) < 1 or int(stdin[1]) > 100000):
        print("Out of range at B[%d]." % (i + 1))
        exit()

    A[i].append(int(stdin[0]))
    A[i].append(int(stdin[1]))

Bsum = 0
for a in A:
    Bsum += a[1]

if (Bsum < M):
    print("Summed B are less than M.")
    exit()

stores = sorted(A)
charge = 0

for store in stores:
    if (M <= 0):
        break
    if (M - store[1] >= 0):
        charge += store[0] * store[1]
        M -= store[1]
    elif (M - store[1] < 0):
        charge += store[0] * M
        M = 0

print(charge)

Submission status: Accepted

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

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

print(cost)

Submission status: Accepted

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

for A, B in sorted(AB):
    if M >= B:
        cost += A*B
        M -= B
        if M == 0:
            break
    else:
        cost += A*M
        break

print(cost)

Submission status: Accepted

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

for i in sorted(AB):
    if M > i[1]:
        price += i[0]*i[1]
        M -= i[1]
    elif M == i[1]:
        price += i[0]*i[1]
        break
    else:
        price += i[0]*M
        break

print(price)

Submission status: Accepted

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

ret = 0    
for x in sorted(lst):
    a, b = x[0], x[1]
    for y in range(b):
        M -= 1
        ret += a
        if  M == 0:
            print(ret)
            exit(0)

Submission status: Accepted

Solution code:
N,M = map(int, raw_input().split())
ab = [[0 for i in range(2)] for j in range(N)]
for i in range(N):
    ab[i][0], ab[i][1] = map(int, raw_input().split())
AB = sorted(ab, key=lambda x:x[0])
count = 0
total = 0
for AB_ in AB:
    num = min(M, AB_[1])
    total += AB_[0]*num
    M -= num
print total

Submission status: Accepted

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

	total = 0
	rest = m
	for i in range(n):
		if p[i][1] > rest:
			total += p[i][0]*rest
			break
		rest -= p[i][1]
		total += p[i][0] * p[i][1]
	print(total)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

cost = 0
drinks = 0
for a, b in ab:
    after = drinks + b
    if after > m:
        cost += (m - drinks) * a
        break
    cost += a * b
    drinks += b
print(cost)

Submission status: Accepted

Solution code:
from operator import itemgetter
A = []

def main():
    accum = 0
    cost = 0
    N, M = map(int, input().split())
    for i in range(N):
        A.append(list(map(int, input().split())))
    B = sorted(A, key = itemgetter(0))
    while accum < M:
         eB = B.pop(0)
         if accum + eB[1] > M:
             cost += eB[0] * (M - accum)
             accum = M
         else:
             accum += eB[1]
             cost += eB[0] * eB[1]
    print(cost)

main()

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

sum = 0
num = m
for i in range(n):
	if(0 >= num):
		break
	sum += ab[i][0]*min(ab[i][1],num)
	num -= ab[i][1]

print(sum)

Submission status: Accepted

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

# # Bubble Sort
# start = 0
# for i in range(N-1):
#     for index in range(start, N-1):
#         if AB[index][0] > AB[index+1][0]:
#             AB[index], AB[index+1] = AB[index+1], AB[index]
#         else:
#             pass
#         start += 1

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

final = 0
sum_bottles = 0
while(M > sum_bottles):
    final += 1
    sum_bottles += AB[final-1][1]

cost = 0
sum_bottles = 0
for i in range(final):
    if i == final - 1:
        cost += AB[i][0] * (M - sum_bottles)
    else:
        cost += AB[i][0] * AB[i][1]
        sum_bottles += AB[i][1]

print(cost)

Submission status: Accepted

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

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

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

# O(M)
cnt = 0 # counter of drink
prc = 0 # price of drink
i = 0
while cnt < M:
    a, b = AB[i]
    if cnt+b <= M:
        cnt += b
        prc += a*b
    else:
        prc += a*(M-cnt)
        cnt = M
    i+=1

print(prc)

Submission status: Accepted

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

for A, B in lst:
    if M == 0:
        break
    for i in range(B):
        price += A
        M -= 1
        if M == 0:
            break

print(price)

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.sort()
n = 0
ans = 0
for i in range(N):
    A,B = l[i]
    if n+B <= M:
        ans += A*B
        n += B
    else:
        ans += A*(M-n)
        n += M-n
    if n==M:
        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(reverse = False)

money = 0

for j,k in li:
    money += j * min(k,m)
    m -= k
    if m <= 0:
        break

print(money)

Submission status: Accepted

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

money = 0
count = 0

while m > 0:
    if m > li[count][1]:
        money += li[count][0] * li[count][1]
        m -= li[count][1]
        count += 1
    else:
        money += li[count][0] * m
        m = 0
        count += 1

print(money)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[]
for i in range(N) :
  A=list(map(int,input().split()))
  L.append(A)
L.sort()
P=0
for j,k in L :
  P+=j*min(k,M)
  M-=k
  if M<=0 :
    break
print(P)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[]
for i in range(N) :
   A=list(map(int,input().split()))
   L.append(A)
L.sort()
X=Y=P=0
for i in range(N) :
  X=Y+L[i][1]
  if X<M :
    P=P+L[i][0]*L[i][1]
    Y=Y+L[i][1]
  else :
    P=P+L[i][0]*(M-Y)
    break
print(P)

Submission status: Accepted

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

AB_list=[]

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

AB_list = sorted(AB_list)
cost = 0
num = 0
for AB in AB_list:
    num = AB[1]
    if M > num:
        cost += AB[0]*num
        M -= num
    else:
        cost += AB[0]*M
        break

print(cost)

Submission status: Accepted

Solution code:
def main():

    N, M = map(int, input().split())
    data = [None] * N
    for n in range(N):
        data[n] = [int(x) for x in input().split()]

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

    m = 0
    y = 0
    for n in range(N):
        if m + data[n][1] > M:
            y += (M - m) * data[n][0]
            break
        else:
            y += data[n][1] * data[n][0]
            m += data[n][1]

    print(y)


main()

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
L = [list(map(int, input().split())) for i in range(N)]
L.sort(key=lambda x: x[0])
c = 0
for i in range(N):
    if M <= L[i][1]:
        print(c + L[i][0] * M)
        exit()
    else:
        M -= L[i][1]
        c += L[i][0] * L[i][1]

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
A = []
B = []
ta = 0
tb = 0
# for i in range(N):
#     ta, tb = map(int, input().split())
#     A.append(ta)
#     B.append(tb)
# print(A,B)
L = [list(map(int,input().split())) for i in range(N)]
#print(L)
L.sort(key=lambda x: x[0])
#print(L)
c = 0
for i in range(N):
    if M <= L[i][1]:
        print(c + L[i][0] * M)
        exit()
    else:
        M -= L[i][1]
        c += L[i][0] * L[i][1]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Energy Drink Collector
https://atcoder.jp/contests/abc121/tasks/abc121_c

"""
import sys


def solve(stores, M):
    total_price = 0
    for s in stores:
        if M <= s[1]:
            return total_price + (s[0] * M)
        total_price += (s[0] * s[1])
        M -= s[1]
    return -1


def main(args):
    N, M = map(int, input().split())
    stores = sorted([[int(i) for i in input().split()] for _ in range(N)])
    ans = solve(stores, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

n,m = map(int,input().split())
cost = []
for i in range(n):
    a,b = map(int,input().split())
    cost.append([a,b])
cost.sort()
res = 0
cnt = 0
for i in range(n):
    if cost[i][1] >= m-cnt:
        res += cost[i][0]*(m-cnt)
        break
    else:
        res += cost[i][0]*cost[i][1]
        cnt += cost[i][1]
print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

price_to_nums = defaultdict(int)
for i in range(N):
    a, b = map(int, input().split())
    price_to_nums[a] += b

prices = sorted(list(price_to_nums.keys()))

total = 0
left = M
for i in range(len(prices)):
    price = prices[i]
    c = min(price_to_nums[price], left)
    total += c * price
    left -= c
    if left <= 0:
        break

print(total)

Submission status: Accepted

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

ans = 0

while(M > 0):
    for j in range(N):
        ans += drink[j][0] * min(M, drink[j][1])
        if M >= drink[j][1]:
            M -= drink[j][1]        
        else:
            M = 0
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(j) for j in input().split()])
ab.sort()

cost = 0
for i in range(n):
  if m == 0:
    break
  buy_num = min(m,ab[i][1])
  m -= buy_num
  cost += buy_num * ab[i][0]
print(cost)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(n)))
c = sorted(zip(a, b))
cost = 0
rest = m
for a, b in c:
    if rest >= b:  # bを足すだけの余裕があるとき
        cost += a * b
        rest -= b
    else:  # b本は買えないとき買えるのはm本
        cost += a * rest
        break
print(cost)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A, B = zip(*(map(int, input().split()) for _ in range(N)))
C = sorted(zip(A, B))
ans = 0
m = M
for a, b in C:
    if m >= b:
        ans += a * b
        m -= b
    else:
        ans += a * m
        break
print(ans)

Submission status: Accepted

Solution code:
def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])])
    ans = 0
    for a, b in ab:
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, m, *ab = map(int, string.split())
    ans = 0
    for a, b in sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])]):
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
def solve(string):
    n, m, *ab = map(int, string.split())
    ans = 0
    for a, b in sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])]):
        ans += a * min(b, m)
        m -= b
        if m <= 0:
            break
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
num = []
for i in range(N):
    a,b = map(int,input().split())
    li = [a,b]
    num.append(li)
num.sort()
yen = 0
for i in range(N):
    if num[i][1] < M:
        yen += (num[i][0] * num[i][1])
        M -= num[i][1]
    else:
        yen += num[i][0] * M
        break
print(yen)

Submission status: Accepted

Solution code:
def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])], key=lambda x: x[0])
    ans = 0
    for a, b in ab:
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Submission status: Accepted

Solution code:
import numpy as np
def solve(n, m, a, b):
    records = sorted(list(zip(a, b)), key=lambda _: _[0])
    cnt = 0
    res = 0
    for a_i, b_i in records:
        next = cnt + b_i
        if m <= next:
            c = m - cnt
            res += a_i * c
            break
        else:
            res += a_i * b_i
        cnt = next
    return res

n, m = map(int, input().split())
a, b = np.zeros(n, dtype=int), np.zeros(n, dtype=int)
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, m, a, b))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
dataset=sorted([tuple(map(int,input().split())) for i in range(n)])
ans=0
for data in dataset:
  if m==0:
    print(ans)
    exit()
  tmp=min(data[1],m)
  ans+=tmp*data[0]
  m-=tmp
print(ans)

Submission status: Accepted

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

for n in range(N):
    cost = AB[n][0]
    max_buy = AB[n][1]
    for mb in range(max_buy):
        min_pay += cost
        num_buy += 1
        if num_buy == M:
            print(min_pay)
            exit()

Submission status: Accepted

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

Submission status: Accepted

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

m = 0
c = 0
for AB in ABs:
    a, b = AB
    for _ in range(b):
        m += a
        c += 1
        if c >= M:
            break
    else:
        continue
    break

print(m)

Submission status: Accepted

Solution code:
storeNum, target = map(int, input().split(' '))
stores = []

for i in range(storeNum):
    cost, mx = map(int, input().split(' '))
    stores.append((cost, mx))

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

totalCost = 0
totalCan = 0
for cost, cans in stores:
    totalCost += cost * cans
    totalCan += cans
    if target <= totalCan:
        totalCost -= (totalCan - target) * cost
        print(totalCost)
        break

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
num_dict = dict()
A_list = []
B_list = []

for n in range(N):
  A, B = map(int, input().split())
  num_dict.setdefault(A, 0)
  num_dict[A] += B
  A_list.append(A)

A_list = list(set(A_list))
A_list.sort()
b_accum = 0
all_pay = 0

for a in A_list:
  if M <= b_accum:
    break

  if b_accum + num_dict[a] <= M:
    all_pay += num_dict[a] * a
    b_accum += num_dict[a]    
  
  else:
    all_pay += (M - b_accum) * a 
    b_accum += num_dict[a]
    break
    
print(all_pay)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

ans = 0
for k in AB:
    if M > k[1]:
        M -= k[1]
        ans += k[0] * k[1]
    else:
        ans += k[0] * M
        break

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while True:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# import sys
# input = sys.stdin.readline

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

AB = [list(map(int, input().split())) for __ in range(N)]
AB.sort(key=lambda x : x[0])

k = 0
ans = 0
while M > 0:
    if M > AB[k][1]:
        M -= AB[k][1]
        ans += AB[k][0] * AB[k][1]
    else:
        ans += AB[k][0] * M
        break
    
    k += 1

print(ans)

Submission status: Accepted

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

from operator import itemgetter
N, M = map(int, input().split())
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    
l = list(zip(A, B))
l.sort(key=itemgetter(0))
ans = 0
judge = 0
flag = False
for i in range(N):
    for j in range(l[i][1]):
        ans += l[i][0]
        judge += 1
        if judge == M:
            flag = True
            break
    if flag:
        break

print(ans)

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)
price = 0
m = 0

for a, b in AB:
    if m + b < M:
        price = price + a * b
        m = m + b
    elif m + b >=M:
        price = price + a * (M - m)
        m = M
        break

print(price)

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])
buy = 0
money = 0
for i in range(N):
  if buy+ab_[i][1] > M:
    money += (M-buy)*ab_[i][0]
    break
  else:
    money += ab_[i][0]*ab_[i][1]
    buy += ab_[i][1]

print(money)

Submission status: Accepted

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

money = 0

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

while M > 0:
	for i in range(N):
		if S[i][1] <= M:
			money += S[i][0] * S[i][1]
			M -= S[i][1]
		else:
			money += S[i][0] * M
			M -= M
			break
print(money)

Submission status: Accepted

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

S.sort()
m=0
while M>0:
    for i in range(N):
        if S[i][1]<=M:
            m+=S[i][0]*S[i][1]
            M-=S[i][1]
        else:
            m+=S[i][0]*M
            M=0
            break

print(m)

Submission status: Accepted

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

res=0
ab.sort()
for a,b in ab:
    if b<M:
        M-=b
        res+=a*b
    else:
        res+=a*M
        break
print(res)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    ts = sorted(tuple(map(int, input().split())) for _ in range(n))
    res = 0
    i = 0
    while m > 0:
        b = min(ts[i][1], m)
        res += ts[i][0] * b
        m -= b
        i += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for info in l:
  a, b = info
  if m <= b:
    print(ans + m * a)
    break
  else:
    ans += a * b
    m -= b

Submission status: Accepted

Solution code:
import numpy as np
N, M = list(map(int, input().split()))
data = []
for i in range(N):
  data.append(list(map(int, input().split())))
data = np.asarray(data)
data = data[np.argsort(data[:, 0], axis=0)]

res = 0
for info in data:
  for i in range(info[1]):
    M -= 1
    res += info[0]
    if M==0:
      break
  if M==0:
    break
print(res)

Submission status: Accepted

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

AB=[]
#B=[]

#print(N,M)

#AB[i][0]→A
#AB[i][1]→B

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

"""
for i in range(N):
    print(AB[i][0],AB[i][1])
"""

AB.sort()
"""
for i in range(N):
    print(AB[i][0],AB[i][1])
"""    
ySum=0
dSum=0
for i in range(N):
    cnt=0
    while(cnt<AB[i][1]):
        if(dSum==M):
            break
        ySum=ySum+AB[i][0]
        cnt+=1
        dSum+=1
            
print(ySum)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
c=0;d={}
for _ in[0]*n:
 a,b=map(int,input().split())
 if not a in d.keys():
  d[a]=0
 d[a]+=b
for k in sorted(d.keys()):
 if d[k] < m:
  c+=k*d[k]
  m-=d[k]
 else:
  c+=k*m
  m=0
 if m == 0:break
print(c)

Submission status: Accepted

Solution code:
from operator import itemgetter

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

b.sort(key=itemgetter(0))
#print('ソート後(0番目の要素)：{}'.format(b))

c=0 #個数
d=0 #値段
for i in range(N):
    c+=b[i][1]
    d+=b[i][0]*b[i][1]
    if c>M:
        d-=(c-M)*b[i][0]
        break
print(d)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
drink = []
for _ in range(N):
    drink.append(list(map(int, input().split())))
drink = sorted(drink)
money = 0
honsuu = 0
for i in range(N):
    if honsuu + drink[i][1] <= M:
        money += drink[i][0] * drink[i][1]
        honsuu += drink[i][1]
    else:
        money += drink[i][0] * (M-honsuu)
        break
print(money)