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())
mise=[]
for i in range(n):
  mise.append(list(map(int,input().split())))
ans=0
mise.sort()
i=0
while m>mise[i][1]:
  ans+=mise[i][0]*mise[i][1]
  m-=mise[i][1]
  i+=1
ans+=m*mise[i][0]
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()
sm = 0
cnt = 0

i = 0
while sm != M:
	cnt += A[i][0]*min(A[i][1],M-sm)
	sm += min(A[i][1],M-sm)
	i += 1

print(cnt)

Submission status: Accepted

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

lis = []

for _ in range(n):
    a,b = map(int, input().split())
    lis.append([a,b])
    
lis = sorted(lis)

total = 0
cash = 0

for i in range(n):
    if total < m:
        total += lis[i][1]
        cash += lis[i][0] * lis[i][1]
        if total >= m:
            total -= lis[i][1]
            cash -= lis[i][0] * lis[i][1]
            for j in range(lis[i][1]):
                while total < m:
                    total += 1
                    cash += lis[i][0]
    else:
        break

print(cash)

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

num, cost = 0, 0
for a, b in AB:
    if num + b > m:
        b = m - num

    num += b
    cost += a * b

    if num == m:
        break

print(cost)

Submission status: Accepted

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

tpls = []
for i in range(N):
    a,b = map(int, input().split())
    tpls.append((a, b))
tpls.sort()
need = 0
now = 0
idx = 0
while now < M:
    a, b = tpls[idx]
    if now + b > M:
        need += a * (M - now)
        now = M
    else:
        need += a*b
        now += b
    idx += 1
print(need)

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

ans = 0
for ab in sorted(AB, key=lambda x: x[0]):
  if M >= ab[1]:
    ans += ab[0] * ab[1]
    M -= ab[1]
  else:
    ans += ab[0] * M
    M = 0
  if M <= 0:
    break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=0
for i in range(n):
    c=ab[i][1]
    if c<m:
        ans+=ab[i][0]*c
        m-=c
    else:
        ans+=ab[i][0]*m
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
N,M,*L=map(int,open(0).read().split());C=0
for a,b in sorted(zip(*[iter(L)]*2)):C+=a*min(M,b);M=max(M-b,0)
print(C)

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
countM=0
for a,b in ab:
    b=min(b,M-countM)
    a*=b
    ans+=a
    countM+=b
    if countM==M:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s_A = sorted(A)

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

Submission status: Accepted

Solution code:
import sys

N,M = map(int,input().split())
s = {}
ans = 0

for i in range(N):
	a,b = map(int,input().split())
	if a in s.keys():
		s[a] += b
	else:
		s[a] = b

s = sorted(s.items(), key=lambda x:x[0])
for store in s:
	price = store[0]
	stock = store[1]
	if M == 0: break

	if M - stock >= 0:
		M -= stock
		ans += (stock * price)
	else:
		for i in range(stock):
			M -= 1
			ans += price
			if M == 0:
				print(ans)
				sys.exit()
print(ans)

Submission status: Accepted

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

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

ans = 0
honsu = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

n, m = map(int, input().split())
a = [-1 for _ in range(n)]
b = [-1 for _ in range(n)]
d = {}
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] not in d:
        d[a[i]] = b[i]
    else:
        d[a[i]] += b[i]

d = sorted(d.items(), key=lambda x:x[0])
num = ans = 0 
for i in range(len(d)):
    tmp = num 
    num += d[i][1]
    if num <= m:
        ans += d[i][0]*d[i][1]
    else:
        ans += d[i][0]*(m-tmp)
        break

print(ans)

Submission status: Accepted

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

l.sort()

drink = 0
shop = 0
money = 0
while drink < m:
  if l[shop][1] == 0:
    shop += 1
  else:
    drink += 1
    money += l[shop][0]
    l[shop][1] -= 1
"""    
    print("shop:",shop)
    print("drink:",drink)
    print("money:",money)
"""
print(money)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n, m = I2()
a = [Intl() for i in range(n)]
a.sort()
i = 0#index
c = 0#コスト
s = 0#本数累積和
while s < m:
    s += a[i][1]
    c += a[i][0]*a[i][1]
    i += 1
i -= 1

print(c-a[i][0]*(s-m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
n,m=map(int,input().split())
b=[list(map(int,input().split())) for _ in range(n)]
res=0
ans=0
b.sort(key=lambda x: x[0])
for i in range(n):
    if res+b[i][1]<=m:
        ans+=b[i][0]*b[i][1]
        res+=b[i][1]
    else:
        ans+=b[i][0]*(m-res)
        break
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
count=0
while(count<N):
  if AB[count][1]<=M:
    ans+=AB[count][0]*AB[count][1]
    M-=AB[count][1]
    count+=1
  else:
    ans+=AB[count][0]*M
    break
print(ans)

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
shop = []
count = 0
money = 0
for i in range(N):
    a, b = map(int, input().split())
    shop.append([a, b])

shop = list(sorted(shop))

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

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())
ab = [list(map(int, readline().split())) for _ in range(n)]

ab.sort()

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
num=[]
for i in range(n):
    a,b=map(int,input().split())
    num.append([a,b])
str1= lambda val: val[0]
num.sort(key=str1)
numa=0
numb=0
for i in range(n):
    numa+=(num[i][1])*(num[i][0])
    numb+=num[i][1]
    if numb>=m:
        numa-=(numb-m)*num[i][0]
        break
print(numa)

Submission status: Accepted

Solution code:
# For taking integer inputs.
import math
from decimal import Decimal
from itertools import permutations


def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


n, m = invr()
A = []
for i in range(n):
    A.append(inlist())

A = sorted(A, key=lambda d: d[0])
res = 0
for a in A:
    if m == 0:
        break
    if a[1] >= m:
        res += a[0] * m
        m = 0
    else:
        res += a[0] * a[1]
        m -= a[1]
print(res)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lis = []
for i in range(n):
  lis.append(list(map(int, input().split())))
lis.sort()
ans = 0
for i, j in lis:
  ans += i * min(m, j)
  m -= min(m, j)
print(ans)

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

result = 0
count = 0
flag = False
for i in range(m):
    for j in range(li[i][1]):
        result += li[i][0]
        count += 1
        if count == m:
            flag = True
            break
    if flag:
        break
print(result)

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N, M = inpl()
X = sorted([inpl() for _ in range(N)], key=lambda x: -x[0])
ans = 0
while M:
    a, b = X.pop()
    buy = min(M, b)
    ans += a*buy
    M -= buy
print(ans)

Submission status: Accepted

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

A = [None] * N
B = [None] * N

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

C = zip(A, B)
C = sorted(C)

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

print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    drink = [[int(a) for a in input().split()] for _ in range(N)]
    drink.sort()
    price = 0
    for i in range(N):
        a, b = drink[i]
        if b <= M:
            price += a * b
            M -= b
        else:
            price += a * M
            break
    print(price)

    return  0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
energy = sorted([tuple(map(int,input().split())) for _ in range(n)])
ret = 0
ind = 0
while(m):
  a,b = energy[ind]
  if b > m:
    ret += a * m
    m = 0
  else:
    ret += a * b
    m -= b
  ind += 1
print(ret)

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

gelt = 0
drink = 0
for i in range(len(AB)):
    if drink + AB[i][1] <= M:
        drink += AB[i][1]
        gelt += AB[i][0] * AB[i][1]
    else:
        gelt += (M - drink) * AB[i][0]
        break
        
print(gelt)

Submission status: Accepted

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

array = []
[array.append(list(map(int,input().split()))) for x in range(n)]

total = 0

array.sort()

for yen,num in array:
    if num < m:
        total += yen*num
        m -= num
    else:
        total += yen*m
        break
print(total)

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)
cost=0
x=0
for ab in AB:
    if x+ab[1]<M:
        cost+=ab[0]*ab[1]
        x+=ab[1]
    else:
        cost+=ab[0]*(M-x)
        break
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=sorted(AB)
cost=0
x=0
for ab in AB:
    if x+ab[1]<M:
        cost+=ab[0]*ab[1]
        x+=ab[1]
    else:
        cost+=ab[0]*(M-x)
        break
print(cost)

Submission status: Accepted

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


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

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

Submission status: Accepted

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

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

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

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

ans = 0
for i in range(m):
    a, b = ab[i]
    if b-m >= 0:
        ans += a*m
        print(ans)
        exit()
    else:
        m -= b
        ans += a*b

Submission status: Accepted

Solution code:
#C
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
count = 0
for i in range(n):
    if m < ab[i][1]:
        ans += m * ab[i][0]
        break
    ans += ab[i][0] * ab[i][1]
    m-=ab[i][1]
    if count >= m:
        break
print(ans)

Submission status: Accepted

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

a_b = sorted(a_b,key=lambda x: x[0])
hon = 0
ans = 0
for i in range(n):
    if hon + a_b[i][1] >= m:
        ans += a_b[i][0]*(m-hon)
        break
    else:
        ans += a_b[i][0]*a_b[i][1]
    hon += a_b[i][1]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    AB = [None] * N
    for i in range(N):
        AB[i] = tuple(map(int, input().split()))

    AB.sort(key=itemgetter(0))
    ans = 0
    n_buy = 0
    for A, B in AB:
        if n_buy + B < M:
            n_buy += B
            ans += A * B
        else:
            ans += A * (M - n_buy)
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
cost = [0]*n
lim = [0]*n

tmp = [0]
for i in range(n):
  tmp[0] = input().split()
  cost[i] = int(tmp[0][0])
  lim[i] = int(tmp[0][1])
  
ab = zip(cost,lim)
x = sorted(ab)
a,b = zip(*x)

buy = 0
c = 0
temp = [0]*2
for i in range(0,len(a)):
  #print(a[i],m)
  if(b[i] >= m):
    buy = buy + a[i]*m
    #print(buy)
    break
  else:
    buy = buy + b[i]*a[i] 
    #print(buy)
    m = m - b[i]
    #print(m)
    

print(buy)

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)

vdic = {}

for i in range(N):
  if A[i] not in vdic.keys():
    vdic[A[i]] = B[i]
  else:
    vdic[A[i]] += B[i]
    
Vdic = sorted(vdic.items())
    
count = 0
cost = 0
    
for i in range(len(Vdic)):
  if Vdic[i][1] + count >= M:
    cost += (M - count) * Vdic[i][0]
    break
  else:
    cost += Vdic[i][1] * Vdic[i][0]
    count += Vdic[i][1]
    
print(cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


N, M = map(int, input().split())
drinks = sorted(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for A, B in drinks:
    if M > B:
        ans += A * B
        M -= B
    else:
        ans += A * M
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

AB=[[int(i) for i in input().split()] for j in range(N)]  # 二次元配列入力　二次元マップみたいな入力のとき

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

money = 0
ct = M
for i in AB:
    money += min(ct, i[1]) * i[0]
    ct = ct - min(ct, i[1])
    if ct == 0:
        break
print(money)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]
    
    ans = 0
    i = m
    for a, b in  sorted(ab):
        if i >= 0:
            ans += a * min(i, b)
            i -= min(i, b)
    
    print(ans)
            

if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

c = 0
ans = 0
i = 0
while c < m and i < n:
    a, b = shop[i]
    if c + b >= m:
        ans += (m - c) * a
        c += (m - c)
    else:
        ans += b * a
        c += b
    i += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
n, m = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
arr.sort()
arr = deque(arr)
ans = 0
while m > 0:
    shop = arr.popleft()
    if shop[1] < m:
        ans += shop[0] * shop[1]
        m -= shop[1]
    else:
        ans += shop[0] * m
        break
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
P = sorted([tuple(map(int, input().split())) for i in range(n)])
ans = 0
for x, y in P:
	q = min(m, y)
	ans += x*q
	m -= q
	if m == 0:
		print(ans)
		exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for j in range(n):
    m -= l[j][1]
    money += l[j][0] * l[j][1]

    if m < 0:
        money -= l[j][0] * -m
        break

print(money)

Submission status: Accepted

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

store_list = {}
for _ in range(N):
  A, B = map(int, input().split())
  if A not in store_list:
    store_list[A] = 0
  store_list[A] += B
  
store_list = sorted(store_list.items(), key=lambda x:x[0])

ans = 0
for A,B in store_list:
  num = min(M, B)
  ans += A * num
  M -= num
  if M == 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)]
AB.sort()
ans=0
#print(AB)
for a,b in AB:
    if M>=b:
        M-=b
        ans+=a*b
    else:
        ans+=a*M
        M=0
    if M<=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)]
AB.sort()
ans=0
#print(AB)
for i in range(N):
    if M>=AB[i][1]:
        M-=AB[i][1]
        ans+=AB[i][0]*AB[i][1]
    else:
        ans+=AB[i][0]*M
        M=0
    if M<=0:
        break
print(ans)

Submission status: Accepted

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

l.sort(key=lambda x: x[0])
count=0;cost=0
for i in range(n):
    a,b=l[i][0],l[i][1]
    if count+b>=m:
        cost+=a*(m-count)
        break
    else:
        cost+=a*b
        count+=b
print(cost)

Submission status: Accepted

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

res = 0
cnt = 0
for a, b in AB:
    tmp = M - cnt
    if tmp <= b:
        res += a * tmp
        break
    res += a * b
    cnt += b

print(res)

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
for i in range(N):
  #まだ足りないケース
  if M > AB[i][1]:
    ans += AB[i][0] * AB[i][1]
    M -= AB[i][1]
  else:
    ans += AB[i][0] * M
    break
print(ans)

Submission status: Accepted

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

d={}

for i in range(n):
    A,B=map(int,input().split())

    if A in d:
        d[A]+=B
    else:
        d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0

for i in range(len(l)):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cost = [None] * n
for i in range(n):
    cost[i] = tuple(map(int, input().split()))
cost = sorted(cost)
x = 0
for a, b in cost:
    if m <= 0:
        break
    x += a * min(b, m)
    m -= b
print(x)

Submission status: Accepted

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

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

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:
n, m = map(int, input().split())
a = [0]*n
for i in range(n):
    a[i] = list(map(int, input().split()))

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

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())
    drink = [list(map(int, input().split())) for _ in range(N)]
    drink.sort(key=lambda x: x[0])

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n,m =map(int,input().split())
ls =[list(map(int,input().split())) for _ in range(n)]
ls.sort()
i = 0
j = 0
while True:
    if m - ls[i][1] > 0:
        m = m - ls[i][1]
        j += ls[i][0]*ls[i][1]
        i += 1
    else:
        j += m*ls[i][0]
        print(j)
        sys.exit()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
D=[]
ans=0; count=0
for i in range(N): 
    A,B=map(int,input().split())
    D.append([A,B])
D.sort()
for i in range(N):
    if count==M: break
    if D[i][1]+count<=M:
        count+=D[i][1]
        ans+=D[i][0]*D[i][1]
    else:
        ans+=D[i][0]*(M-count)
        count=M
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N, M = [int(i) for i in input().split()]
    AABB = [list(map(int, input().split())) for _ in range(N)]
    AABB.sort()
    ans = 0
    drink = 0
    for A, B in AABB:
        need = M - drink
        if need <= B:
            ans += A * need
            break
        else:
            ans += A * B
            drink += B
    print(ans)


resolve()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
dict = {}
su = 0
kounyu = 0
 
for i in range(n):
  A,B = map(int,input().split())
  if A in dict:
    dict[A] += B  #同じAがありうる！！！！！！
  else:
    dict[A] = B
  

d = sorted(dict.items())
 
for i in range(10**99):
  if d[i][1] >= m - kounyu:
    print(su + d[i][0]*(m - kounyu))
    exit()
    
  kounyu += d[i][1]
  su += d[i][1]*d[i][0]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Energy Drink Collector
# https://atcoder.jp/contests/abc121/tasks/abc121_c

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

AB.sort()

drink = 0
ans = 0
for a, b in AB:
  num = min(m - drink, b)
  m -= num
  ans += a * num
  if m == 0:
    break

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[[0,0] for i in range(n)]
for i in range(n):
    a,b=map(int,input().split())
    A[i][0]=a
    A[i][1]=b
tmp=0
ans=0
B=sorted(A,key=lambda x:x[0])
for i in range(n):
    if tmp+B[i][1]<m:
        ans+=B[i][1]*B[i][0]
        tmp+=B[i][1]
    elif tmp+B[i][1]>=m:
        s=m-tmp
        ans+=s*B[i][0]
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from operator import itemgetter
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    ds = [tuple(map(int, input().split())) for _ in range(N)]
    ds.sort(key=itemgetter(0))

    ans = 0
    for a, b in ds:
        buy = min(M, b)
        M -= buy
        ans += a * buy
        if not M:
            break
    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(n)], key = lambda x: (x[0],-x[1]))
ans = 0
for i in l:
    if m - i[1]>=0:
        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())
A=[list(map(int,input().split()))for i in range(n)]
A=sorted(A,key=lambda y:y[0])
cnt=0#ドリンクの本数
ans=0
for i in range(n):
    cnt+=A[i][1]
    if m<=cnt:
        over=cnt-m #mを超えた時の超過本数
        ans+=(A[i][0]*A[i][1])-(over*A[i][0])
        break
    else:
        ans+=A[i][0]*A[i][1]
print(ans)