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:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
X.sort(key=lambda x: x[0])
ans = 0
for k in range(N):
    if M == 0:
        break
    buy = min(X[k][1], M)
    M -= buy
    ans += buy * X[k][0]
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_list_sorted = sorted(ab_list, reverse=False, key=lambda x:x[0])

nokori_honsu = M
cost = 0

for ab in ab_list_sorted:
    if ab[1] >= nokori_honsu:
        cost += nokori_honsu * ab[0]
        break
    else:
        cost += ab[1] * ab[0]
        nokori_honsu -= ab[1]
        
print(cost)

Submission status: Accepted

Solution code:
# ABC121C - Energy Drink Collector
import sys
input = sys.stdin.readline

n, m = list(map(int, input().rstrip().split()))
lst = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
ans = 0
for i in lst:
    while i[1] > 0 and m > 0:
        ans += i[0]
        i[1] -= 1
        m -= 1
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.sort()

cnt = 0
money = 0

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

print(money)

Submission status: Accepted

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

import numpy as np

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

ablist=np.array([list(map(int,input().split())) for i in range(n)])

#aの昇順にソート
newablist=ablist[ablist[:,0].argsort(),:]
x=newablist


costcount=0
i=0

while i<n and x[i][1]<= m:
	m -= x[i][1]
	costcount += x[i][0]*x[i][1]
	i += 1

if i < n:
	costcount += m*x[i][0]


print(costcount)

Submission status: Accepted

Solution code:
#C-Energy Drink Collector
#break文を使わないで攻略したい
N, M = map(int, input().split())
lst = []
for i in range(N):
    lst.append([j for j in map(int, input().split())])
#値段が安い順番に並べ直す
lst = sorted(lst)
#最小必要経費
cost = 0
#持っているドリンクの本数
drink = 0
#店の個数だけまわる予定
for i in range(N):
    if (drink + lst[i][1]) <= M:
        drink += lst[i][1]
        cost += lst[i][0] * lst[i][1]
    else:
        cost += lst[i][0] * (M - drink)
        break
print(cost)

Submission status: Accepted

Solution code:
#break文を使わないで攻略したい
N, M = map(int, input().split())
lst = []
for i in range(N):
    lst.append([j for j in map(int, input().split())])
#値段が安い順番に並べ直す
lst = sorted(lst)
#最小必要経費
cost = 0
#持っているドリンクの本数
drink = 0
#店の個数だけまわる予定
for i in range(N):
    if (drink + lst[i][1]) <= M:
        drink += lst[i][1]
        cost += lst[i][0] * lst[i][1]
    else:
        cost += lst[i][0] * (M - drink)
        break
print(cost)

Submission status: Accepted

Solution code:

N, M = [int(x) for x in input().split()]
# N, M < 10 ** 5
# A < 10 ** 9
# B < 10 ** 5

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

rem = M
need = 0
for a, b in sorted(AB):
    if rem > b:
        need += a * b
        rem -= b
    else:
        need += a * rem
        break
print(need)

Submission status: Accepted

Solution code:
n, m = [ int(v) for v in input().split() ]
shop_data = sorted([ tuple( int(v) for v in input().split() ) for i in range(n) ])


cost = 0
for i in shop_data:
	cost += ( i[0] * min(m,i[1]) )
	m -= min(m,i[1])

print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ab.sort()

price = [0 for _ in range(m)]
ii=0

while m > 0:
    m -= ab[ii][1]
    if m >= 0:
        price[ii] = ab[ii][1] * ab[ii][0]
    else:
        price[ii] = abs(m+ab[ii][1]) * ab[ii][0]
    ii += 1
        
print(sum(price))

Submission status: Accepted

Solution code:
#Coding:Utf-8

N,M=map(int, input().split())
A=[]
B=[]
C=[]
count=0
index=0
remain=0
total=0
for i in range(N):
    a,b=map(int, input().split())
    A.append(a)
    B.append(b)


import numpy as np
A=np.array(A)
B=np.array(B)
C=A.argsort()

for j in range(len(C)):
    if count<=M:
        count=count+B[C[j]]
        index+=1
    else:
        break
remain= count- M

for k in range(index):
    total=total+A[C[k]]*B[C[k]]
else:
    print(total-remain*A[C[k]])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ABlist = [tuple(map(int,input().split())) for _ in range(N)]
ABlist.sort()
money = 0
for AB in ABlist:
    maz_num = AB[1]
    maz_pri = AB[0]
    add_m = maz_pri*maz_num
    if M > 0:
        money += add_m
        M -= maz_num
    if M == 0:
        break
    if M < 0:
        while M!=0:
            money -= maz_pri
            M += 1
        break

print(money)

Submission status: Accepted

Solution code:
import sys
from collections import deque
from operator import itemgetter
input = sys.stdin.readline
N, M = map(int, input().split())

A = deque()
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=itemgetter(0))

m=0
cost=0

for i in range(N):
    if m >= M:
        break
    buy = min(M - m, A[i][1])
    cost += A[i][0] * buy
    m += buy

print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# sys.stdin.readline()
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))
ab = sorted(ab)
for c, d in ab:
    if m >= d:
        ans += c*d
        m -= d
    else:
        ans += c*m
        break
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split()) #N...ken M..hon
A=[list(map(int,input().split())) for i in range(N)]
A=sorted(A) #A...en B..hon
#print(A)
price=0
num=0
for i in range(N):
    if num+A[i][1]<M:
        price+=A[i][0]*A[i][1]
        num+=A[i][1]
    elif num<M and num+A[i][1]>=M:
        price+=A[i][0]*(M-num)
        break
    else:
        break
print(price)

Submission status: Accepted

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

ans = 0
res = M
for v in X:
    ans += v[0] * min(v[1], res)
    res -= v[1]
    if res <= 0:
        break
        
print(ans)

Submission status: Accepted

Solution code:
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
cnt = 0
for i, (Ai, Bi) in enumerate(AB):
    if cnt + Bi >= M:
        ans += Ai * (M - cnt)
        break
    else:
        cnt += Bi
        ans += Ai * Bi

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    _, m = [int(e) for e in input().split()]

    N = []
    for l in sys.stdin:
        N.append([int(e) for e in l.strip().split()])
    N.sort(key=lambda x: x[0])
    total = 0
    for l in N:
        if m <= l[1]:
            total += l[0] * m
            m = 0
        else:
            m -= l[1]
            total += l[0] * l[1]
        if m == 0:
            break
    print(total)

main()

Submission status: Accepted

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

count = 0
buy = 0
for a, b in ab:
    for i in range(b):
        buy += a
        count += 1

        if count >= m:
            print(buy)
            exit()

Submission status: Accepted

Solution code:
def intinput():
    return map(int,input().split())

n,m=intinput()
a = [[0,0] for _ in range(n)]
for i in range(n):
    a[i] = list(intinput())
a.sort()
i=0
f=0
while m>0:
    if m>=a[i][1]:
        m -= a[i][1]
        f += a[i][1]*a[i][0]
    else:
        f += a[i][0]*m
        m=0
    i+=1
print(f)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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

    ans = 0
    now = 0
    for a, b in v:
        buy = min(M - now, b)
        ans += buy * a
        now += buy

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

total_pay = 0
for ab in AB:
    M -= ab[1]
    total_pay += ab[1] * ab[0]
    if M < 0:
        total_pay += ab[0] * M
        break
    else:
        pass
        
print(int(total_pay))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort()
total_drink = 0
total_pay = 0
for ab in AB:
    total_drink += ab[1]
    if M < total_drink:
        total_pay += ab[0] * (M - total_drink + ab[1])
        break
    else:
        total_pay += ab[1] * ab[0]
        
print(int(total_pay))

Submission status: Accepted

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

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

xy=sorted(xy)

ans=0
for p,c in xy:
    if m>=c:
        ans+=p*c
        m-=c
    else:
        ans+=p*m
        m=0
        break
print(ans)

Submission status: Accepted

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

for i in range(N):
    shop_i=list(map(int,input().split()))
    shop.append(shop_i)
shop.sort()

i=0
while M>0:
    if M>=shop[i][1]:
        costs+=shop[i][0]*shop[i][1]
        M-=shop[i][1]
    else:
        costs+=shop[i][0]*M
        M=0
    i+=1

print(costs)

Submission status: Accepted

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

A.sort()
ans=0
x=0
for val , pon in A:
	for p in range(pon):
		ans +=val
		x +=1
		if x>=M:
			print(ans)
			exit()

Submission status: Accepted

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

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

A.sort()

x = 0
y = 0

for i,j in A:
  if M - x < j:
    y += i * (M-x)
    break    
  else:
    x += j
    y += i * j

print(y)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
eng=[]
for i in range(n):
    eng.append([int(i) for i in input().split()])
eng.sort()
can=0
mny=0
i=0
while can<m:
    if m-can>=eng[i][1]:
        can+=eng[i][1]
        mny+=eng[i][1]*eng[i][0]
        i+=1
    else:
        mny+=eng[i][0]*(m-can)
        can=m
print(mny)

Submission status: Accepted

Solution code:
N, M = [int(e) for e in input().split(" ")]
ABs = []
for _ in range(N):
    ABs.append([int(e) for e in input().split(" ")])

ABs = list(sorted(ABs))
# print(ABs)
count = M
memMoney = 0
for a,b in ABs:
    if count - b > 0:
        memMoney = memMoney + a*b
        count = count - b
        continue

    if count - b == 0:
        memMoney = memMoney + a*b
        count = count - b
        break

    d = count
    memMoney = memMoney + a*d
    count = count - d
    break

print(memMoney)

Submission status: Accepted

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

Submission status: Accepted

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

ab = sorted(ab)

ans = 0
for p, c in ab:
    if m >= c:
        ans += p * c
        m -= c
    else:
        ans += p * m
        m = 0
        break

print(ans)

Submission status: Accepted

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

A = []
#B = []
for i in range(N):
#    print(i)
#    a, b = map(int, input().split())
    A.append(list(map(int, input().split())))
#    B.append(b)
    
A.sort(key=lambda x: x[0])

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

print(ans)

Submission status: Accepted

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

sum=0
honsu=0
for i in range(n):
    cost=ab[i][0]
    maxhonsu=ab[i][1]
    for _ in range(maxhonsu):
        if honsu==m:
            break
        sum+=cost
        honsu+=1

    if honsu==m:
        break

print(sum)

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
a = []
b = []
dic = {}
count = 0
data = [0] * n
for i in range(n):
    x,y = list(map(int,input().split()))
    data[i] = [x,y]
data = sorted(data,key = lambda x : x[0])
for i in range(n):
    if m > data[i][1]:
        count += data[i][0] * data[i][1]
        m -= data[i][1]
    else:
        count += data[i][0] * m
        break
print(count)

"""
for i in range(n):
    x,y = list(map(int,input().split()))
    dic[x] = y
dic = sorted(dic.items())



for key in dic:
    if m - dic[key] > 0:
        count += key * dic[key]
        m = m - dic[key]
    else:
        count += m * key
        break
print(count)
"""
            

"""

for i in range(n):
    x,y = list(map(int,input().split()))
    a.append(x)
    b.append(y)
count = 0


while m > 0:
    mi = min(a)
    d = a.index(mi)
    if m > b[d]  : # Bi本買う
        m -= b[d]
        count += b[d] * mi
    else:
        count += m * mi
        break
    del a[d]
    del b[d]
print(count)



"""

Submission status: Accepted

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

def getKey(item):
    return item[0]

arr.sort(key=getKey)

ans=0
for i in range(N):
    if M==0:
        break
    a,b=arr[i]
    if M >= b:
        ans=ans+(b*a)
        M = M - b
    else:
        ans=ans+(M*a)
        M=0

print(ans)

Submission status: Accepted

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

a = []
b = []
for i in range(n):
    a.append(ab[i][0])
    b.append(ab[i][1])

import numpy as np

a_argsort = np.argsort(a)
counter_m = 0
counter_money = 0
for i in range(n):
    idx = a_argsort[i]
    _b = b[idx]
    _a = a[idx]
    if counter_m + _b >= m:
        buy = m - counter_m
        counter_money += buy * _a
        break
    else:
        counter_m += _b
        counter_money += _a * _b

print(counter_money)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
count=0
list=list([])
while count < n:
    list.append([int(i) for i in input().split()])
    count+=1
count=0
amount=0
for l in sorted(list):
    c = l[1] if m-count>l[1] else m-count
    amount += l[0]*c
    count += c
    if count == m:
        break
print(amount)

Submission status: Accepted

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

c=i=0
while M:
    if (s[i][1]<M):
        c += s[i][0]*s[i][1]
        M -= s[i][1]
    else:
        c += s[i][0]*M
        M = 0
    i+=1
print(c)

Submission status: Accepted

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

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 x:x[0])
ans = 0
nokori = m
i = 0
while nokori > 0:
    ans += ab[i][0] * min(ab[i][1], nokori)
    nokori -= ab[i][1]
    i += 1
print(ans)

Submission status: Accepted

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

dict = {}

for i in range(n):
    a, b = [int(j) for j in input().split()]
    if  (a in dict):
        dict[a] = b + dict[a]
    else:
        dict[a] = b

sum = m
price = 0

for k, v in sorted(dict.items()):
    if sum > v:
        sum -= v
        price += k * v
    else:
        price += k * sum
        break

print(price)

Submission status: Accepted

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

minCost = 0
for (cost,q) in stores:
    if(q > M):
        minCost += M*cost
        break
    else:
        M -=q
        minCost += q*cost
print(minCost)

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

print(value)

Submission status: Accepted

Solution code:
N, M = [int(nm) for nm in input().split()]
AB = []
for n in range(N):
  A, B = [int(ab) for ab in input().split()]
  AB.append([A, B])
AB.sort()
money = 0
while M > 0:
  Ai, Bi = AB[0][0], AB[0][1]
  if Bi <= M:
    money += Ai * Bi
    M -= Bi
  else:
    money += Ai * M
    M = 0
  AB.remove(AB[0])
print(money)

Submission status: Accepted

Solution code:
from operator import itemgetter

NM = list(map(lambda x: int(x), input().split()))
N = NM[0]
M = NM[1]

stores = [list(map(lambda x: int(x), input().split())) for i in range(N)]
stores = sorted(stores, key=itemgetter(0))

answer = 0
stock = 0
for store in stores:
  if (M > store[1]):
    M = M - store[1]
    answer += store[0] * store[1]
  else:
    answer += store[0] * M
    break

print(answer)

Submission status: Accepted

Solution code:
# coding:utf-8

N, M = map(int, input().split())
NL = []
summoney = []
min = 1000000000

for i in range(N):
    *A, B = map(int, input().split())
    A.append(B)
    NL.append(A)

NL = sorted(NL)

for j in range(N):
    if M - NL[j][1] >= 0:
        summoney.append(NL[j][0]*NL[j][1])
        M =  M - NL[j][1]
    elif  M - NL[j][1] < 0:
        summoney.append(M*NL[j][0])
        break

print(sum(summoney))

Submission status: Accepted

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


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB1 = zip(A,B)
    AB2 = sorted(AB1, key=lambda t:t[0])

    m = M
    s = 0
    for ab in AB2:
        if m > ab[1]:
            m -= ab[1]
            s += ab[0] * ab[1]
        else:
            s += ab[0] * m
            break

    print(s)



# Generated by 1.1.4 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():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]" 
    B = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
para_val = {}
for i in range(n):
    a, b = map(int,input().split())
    if a in para_val.keys() :
        para_val[a] += b

    else : para_val[a] = b
    
para_val  = sorted(para_val.items())
count = m
ans = 0

    
for i, j in para_val :
    if count > 0 :
        if j <= count :
            count = count - j 
            ans += i * j 
        else : 
            ans += count*i 
            count = 0
    else : break 
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x:x[0])
answer = 0
for ab in AB:
    if ab[1] <= M:
        answer += (ab[0]*ab[1])
        M -= ab[1]
    else:
        answer += (ab[0]*M)
        M = 0
        break
        
print(answer)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
E  = []
for i in range(N):
  E.append(list(map(int,input().split())))
#print(E)
E.sort(key=lambda x:x[0])
#print(E)
ans = 0
i = 0
while M > 0:
  A, B = E[i]
  ans += A * min(B,M)
  M = max(M-B,0)
  i+=1
print(ans)

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

ans = 0
for i in ab:
	if m <= i[1]:ans+=m * i[0]
	else:ans+=i[0] * i[1]
	m-=i[1]
	if m < 0:break

print(ans)

Submission status: Accepted

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

n, m = map(int, input().split())
drink = []
for _ in range(n):
    drink.append([int(s) for s in input().split()])
    
drink.sort()

bottle = 0
pay = 0

for i in range(n):
    bottle += drink[i][1]
    pay += drink[i][0]*drink[i][1]
    if bottle > m:
        bottle -= drink[i][1]
        pay -= drink[i][0]*drink[i][1]
        idx = i
        break
    
if bottle != m:
    pay += (m-bottle)*drink[idx][0]

print(pay)

Submission status: Accepted

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

def tupVal(tup):
    return tup[0]
tupList.sort(key = tupVal)
ans = 0
for i in tupList:
    if m >= i[1]:
        ans += i[0] * i[1]
        m -= i[1]
    else:
        ans += i[0] * m
        break
print(ans)

Submission status: Accepted

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

ans=0
i=0
while M>0:
  A,B=E[i]
  ans+=A*min(B,M)
  M=max(M-B,0)
  i+=1
print(ans)

Submission status: Accepted

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

cnt=0
amnt=0
for i in AB:
  if cnt>=M:
    break
  elif cnt + i[1]>M:
    for j in range(1,i[1]):
      if cnt>=M:
        break
      else:
        cnt += 1
        amnt += i[0]
  else:
    cnt += i[1]
    amnt += i[0]*i[1]
print(amnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split(" "))
C=[]
for _ in range(N):
    a,b=map(int, input().split(" "))
    C.append((a,b))
#C = [(6,18),(2,5),(3,10),(7,9)]

C.sort(key=lambda x:x[0])
a = 0
n = 0
for c in C:
    if n + c[1] >= M:
        a += (M-n) * c[0]
        #n += 
        break
    else:
        a += c[0] * c[1]
        n += c[1]
print(a)

Submission status: Accepted

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

# スペース区切りの整数の入力
N,M = map(int, input().split())
AB_list = []

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

AB_list.sort(reverse=False) 

#print(AB_list)

sum = 0
i = 0
ans=0

while(sum!=M):
  #print(AB_list[i][0],AB_list[i][1])
  if sum + AB_list[i][1] <=M: #全部買っても合計に達しないなら
    #print("全部買う")
    sum = sum + AB_list[i][1] #全部買う
    ans = ans + AB_list[i][1]*AB_list[i][0] #全部買った分、金額増加
    #print(sum,ans)
  else: #買い占めると合計超すので抑える
    #print("一部買う")
    ans = ans + AB_list[i][0]*(M-sum) #買った分金額増加
    #print(M-sum,ans)
    sum=M #これで止める
  i=i+1
  
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
#lst=[map(int,input().split()) for _ in range(n)]
lst=[list(map(int,input().split())) for _ in range(n)]
sl=sorted(lst,key=lambda x:x[0])
count=0
target_row,target_b=0,0
for i in range(len(sl)):
    if count + sl[i][1] > m:
        target_row = i
        target_b = m-count
        #print('break',i)
        break
    count+=sl[i][1]
    if i==len(sl)-1:
        target_row = i
        target_b = sl[i][1]
    #print('pass',i)
result=0
for i in range(target_row):
    result+=sl[i][0]*sl[i][1]
    #print('test',result)
    
#print('sorted_list ')
#print(sl)
#print('target_row : ',target_row,'  b :',target_b)
print(result+sl[target_row][0]*target_b)

Submission status: Accepted

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

v = 0
s_b = 0
lst2 = []
for a, b in lst:
    v += a * b
    s_b += b
    if s_b == m:
        print(v)
        exit()
    if s_b > m:
        lst2.append([a, b])
        break
        
lst2.append([v, s_b])
t_v = lst2[1][0] - ((lst2[1][1] - m) * lst2[0][0])
print(t_v)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
ABs = [inpl() for _ in range(N)]
ABs.sort()

ind = 0
ans = 0
cnt = 0
while cnt < M:
    ans += ABs[ind][0]
    ABs[ind][1] -= 1
    if ABs[ind][1] == 0:
        ind += 1
    cnt += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
nl = set(range(n))
ab = [list(map(int, input().split())) for _ in nl]
ab.sort()
num, ans = 0, 0
for a, b in ab:
    if num + b < m:
        num += b
        ans += a * b
    else:
        ans += a * (m - num)
        break
print(ans)

Submission status: Accepted

Solution code:
import heapq as hq

def main():
    n,m = list(map(int,input().split(' ')))
    shop = []
    cnt = 0
    total = 0
    for i in range(n):
        hq.heappush(shop,list(map(int,input().split(' '))))
    for i in range(n):
        price,item=hq.heappop(shop)
        if cnt + item <=m:
            cnt += item
            total += price*item
            if cnt ==m:
                break
        else:
            total += price*(m - cnt)
            break

    print(total)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

AB.sort()

ans = 0
count = 0
for li in AB:
    if M - count >= li[1]:
        count += li[1]
        ans += li[0]*li[1]
    else:
        ans += li[0]*(M-count)
        break

print(ans)

Submission status: Accepted

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

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

shop.sort()

count = 0
money = 0
for i in range(N):
    if count == M:
        break
    elif count + shop[i][1] <= M:
        count += shop[i][1]
        money += shop[i][0] * shop[i][1]
    elif count + shop[i][1] > M:
        money += shop[i][0] * (M - count)
        count += M - count

print(money)

Submission status: Accepted

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

ab_price = [0] * n
num = [0] * (n+1)

for i in range(n):
    num[i+1] = num[i] + sorted_ab[i][1]
    ab_price[i] = sorted_ab[i][0] * sorted_ab[i][1]
    if num[i+1] >= m:
        to_here = i + 1
        break

max_price = sorted_ab[to_here-1][0]
minus_num = num[to_here] - m
ans = sum(ab_price[:to_here]) - max_price * minus_num

print(ans)

Submission status: Accepted

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

shop.sort()

sum = 0
remain = M
for i in range(0, len(shop)):
    price = shop[i][0]
    stock = shop[i][1]

    if remain - stock >= 0:
        sum += price * stock
        remain -= stock
    else:
        sum += price * remain
        break

#print(N)
#print(M)
#print(shop)
print(sum)

Submission status: Accepted

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

drinkinfo = []  #prices and numbers of drinks

#get input data
for i in range(N):
    A,B = (int(k) for k in input().split())
    drinkinfo.append([A,B])

#sort drinks in price
sorteddrink = sorted(drinkinfo, key = lambda x:(x[0]), reverse = False)

price = 0 #answer
numdrink = 0 #number of drinks

#perform greedy algorithm
for i in range(N):
    if sorteddrink[i][1] <= (M - numdrink):
        price += sorteddrink[i][1] * sorteddrink[i][0]
        numdrink += sorteddrink[i][1]
    else:
        price += sorteddrink[i][0] * (M - numdrink)
        numdrink += (M - numdrink)

    if numdrink == M:
        break

print(price)

Submission status: Accepted

Solution code:
#input
N, M = [int(i) for i in input().split(" ")]
AB = []
money = 0
for i in range(N):
  AB.append([int(i) for i in input().split(" ")])
BA = sorted(AB)

for i in BA:

  if i[1] < M:
    M = M - i[1]
    money += i[0] * i[1]
  else :
    money += i[0] * M
    break
  

print(money)