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

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

cost = 0

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

print(cost)

Submission status: Accepted

Solution code:
import sys

s = input().split(" ")
n = int(s[0])
m = int(s[1])
a = []
for i in range(n):
	s = input().split(" ")
	a.append([int(s[0]), int(s[1])])

a.sort()
cnt = 0
ans = 0
for i in range(n):
	d = min(m-cnt, a[i][1])
	ans += d*a[i][0]
	cnt += d
	if cnt == 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_s=sorted(AB)

ans=0
cnt=0
for a,b in AB_s:
    ans+=a*b
    cnt+=b
    if cnt>=M:
        ans-=a*(cnt-M)
        print(ans)
        exit()

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

h=0
k=0
i=0
while h+AB[i][1]<M:
    h+=AB[i][1]
    k+=AB[i][0]*AB[i][1]
    i+=1

k+=AB[i][0]*(M-h)

print(k)

Submission status: Accepted

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

AB = []

for _ in range(N):

    AB.append([int(x) for x in input().split()])

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

current_drinks = 0

current_buget = 0

for a, b in AB:

    num_buy = min(b, (M-current_drinks))

    current_drinks += num_buy

    current_buget += num_buy*a

    # print(current_drinks, current_buget)

    if current_drinks == M:

        break

print(current_buget)

Submission status: Accepted

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

ab.sort()

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

print(res)

Submission status: Accepted

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

ans = 0
tmp = 0 
for r in sorted(AB):
    buy = min(M-tmp, r[1])
    tmp += buy
    ans += r[0] * buy
    if tmp == M:
        break
        
print(ans)

Submission status: Accepted

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

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

ab.sort()
ans = 0
num = 0
i = 0

while num < m:
    t = min(ab[i][1], m - num)
    ans += ab[i][0] * t
    num += t
    i += 1


print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ab = [0]*n
for i in range(n):
    a, b = map(int, input().split())
    ab[i] = (a, b)
ab.sort()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int, input().split())
stores = [tuple(map(int, input().split())) for _ in range(N)]
stores.sort()
total = 0
for store in stores:
    if store[1] < M:
        M -= store[1]
        total += store[0] * store[1]
    else:
        total += store[0] * M
        break
print(total)

Submission status: Accepted

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


def main():
    N, M = map(int, input().split())
    Q = []
    for _ in range(N):
        a, b = map(int, input().split())
        Q.append([a, b])
    heapq.heapify(Q)
    
    ans = 0
    cnt = 0
    while cnt<M:
        a, b = heapq.heappop(Q)
        ans += a * min(b, M-cnt)
        cnt += b

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    (N,M) = (int(i) for i in input().split())
    AB = [[int(j) for j in input().split()] for i in range(N)]
    AB.sort()
    cost=0
    for i in AB:
        if i[1] >= M:
            cost += M*i[0]
            print(cost)
            break
        else:
            cost += i[0]*i[1]
            M -= i[1]


if __name__ == "__main__":
    resolve()

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
ans = 0

for i in range(n):

    if count + ab[i][1] >= m:
        ans += ab[i][0] * (m - count)
        print(ans)
        exit()

    else:
        count += ab[i][1]
        ans += ab[i][0] * ab[i][1]

Submission status: Accepted

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

ans = 0
i = 0
while M:
  if L[i][1] < M:
    ans += L[i][0] * L[i][1]
    M -= L[i][1]
  else:
    ans += L[i][0] * M
    M = 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)]
AB.sort()
#print(AB)
sum = 0
ans = 0
i = 0
while sum < M:
    ans += AB[i][0]*min(AB[i][1],M-sum)
    sum = sum+AB[i][1]
    i +=1
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.sort()
ans = 0
for i in range(n):
    if a[i][1] < m:
        ans += a[i][0] * a[i][1]
        m -= a[i][1]
    else:
        ans += a[i][0] * m
        break
print(ans)

Submission status: Accepted

Solution code:
# N, M = map(int, input().split())
# A = []
# for i in range(N):
#     a = list(map(int, input().split()))
#     A.append(a)
# A = sorted(A)
#
# count = 0
# cost = 0
#
# i = 0
# while count < M:
#     cost += A[i][0] * min(A[i][0], M-count)     # 買う予定の本数に満たしたかどうかをmin()で判断
#     count += min(A[i][0], M-count)              # 上と同じくmin()で判断
#     i += 1
#
# print(cost)

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

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

A = sorted(A)

count = 1
b = 0
cost = 0
for i in range(M):
    if i == M:
        break

    cost += A[b][0]

    if count == A[b][1]:
        count = 1
        b += 1
    else:
        count += 1


print(cost)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
drink, sumA, sumB = [], 0, 0
for _ in range(N):
    A,B = map(int, input().split())
    drink.append([A, B])
    sumA += A*B
    sumB += B 

if M == sumB:
    print(sumA)
elif M > sumB // 2:
    drink.sort(reverse=True)
    ans, exM = sumA, sumB - M
    while exM > 0:
        AB = drink.pop(0)
        b = min(exM, AB[1])
        ans -= b * AB[0]
        exM -= b
    print(ans)
else:
    drink.sort()
    ans = 0
    while M > 0:
        AB = drink.pop(0)
        b = min(M, AB[1])
        ans += b * AB[0]
        M -= b
    print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
stores=[]
for i in range(n):
  a,b=map(int,input().split())
  stores.append([a,b])
stores=sorted(stores, key=lambda x: x[0])
ans=0
i=0
while m>0:
  ans+=stores[i][0]*min(m,stores[i][1])
  m-=stores[i][1]
  i+=1
print(ans)

Submission status: Accepted

Solution code:
import heapq
N,M=map(int,input().split())
AB=[]
for i in range(N):
  a,b=map(int,input().split())
  heapq.heappush(AB,[a,b])
ans=0
bought=0
while bought!=M:
  lst=heapq.heappop(AB)
  A,B=lst[0],lst[1]
  if bought+B<=M:
    ans+=A*B
    bought+=B
  else:
    ans+=A*(M-bought)
    bought=M
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ab = []
for _ in range(n):
  ab.append(list(map(int,input().split())))
ab.sort()
ans = 0
for i in range(n):
  a,b = ab[i]
  if m > b:
    m -= b
    ans += a * b
  else:
    ans += a * m
    break
  #print(m,ans)
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()
total = 0

for a, b in ab:
    num = min(b, m)
    total += a * num
    m -= num
    if m <= 0:
        break
print(total)

Submission status: Accepted

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

ans = 0

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

sai = sorted(range(len(a)), key=lambda k: a[k])

for i in range(n):
    bsai = min(m,b[sai[i]])
    m -= bsai
    ans += a[sai[i]]*bsai


print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

AB=AB[np.argsort(AB[:, 0])]

money=0
cans=0
shop=0
while cans<M:
  if cans+AB[shop, 1]<=M:
    money+=AB[shop, 0]*AB[shop, 1]
    cans+=AB[shop, 1]
  else:
    money+=AB[shop, 0]*(M-cans)
    cans+=AB[shop, 1]
    
  shop+=1
    
print(money)

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])
 
y = 0
 
for i in range(len(AB)):
    p = min(M, AB[i][1])
    M -= p
    y += p*AB[i][0]
    if M == 0:
        break
 
print(y)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    ab.sort()
    ans = 0
    cnt = 0
    for i in range(n):
        for j in range(ab[i][1]):
            ans += ab[i][0]
            cnt += 1
            if cnt == m:
                print(ans)
                exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

a = []

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

a.sort()

i = 0
ans = 0

while m > 0:
    if m > a[i][1]:
        ans += a[i][0] * a[i][1]
        m = m - a[i][1]
        i += 1
    else:
        ans += a[i][0] * m
        print(ans)
        sys.exit()

Submission status: Accepted

Solution code:
#C - Energy Drink Collector(ABC121)
N,M=map(int, input().split())
X=[]
for i in range(N):
    a,b=map(int, input().split())
    X.append([a,b])
X.sort()
ans=0
i=0
while M>0:
    if M>=X[i][1]:
        ans+=X[i][1]*X[i][0]
        M-=X[i][1]
        i+=1
    else:
        ans+=X[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.sort(key=lambda x : x[0])

total_money = 0

for i in range(len(AB)):
    buy_cnt = min(M, AB[i][1])
    M -= buy_cnt
    total_money += buy_cnt*AB[i][0]
    if M == 0:
        break

print(total_money)

Submission status: Accepted

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

List.sort()
money = 0
d = 0
for i in range(N):
    if d >= M:
        break
    elif d+List[i][1] <= M:
        d += List[i][1]
        money += List[i][0]*List[i][1]
    elif d+List[i][1] > M:
        money += (M-d)*List[i][0]
        d = M

print(money)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(n)]
li.sort()
i=0
goukei=0
goukeiM=0
while goukei<m:
  if li[i][1]+goukei<=m:
    goukei+=li[i][1]
    goukeiM+=(li[i][1])*(li[i][0])
    i+=1
  else:
    goukeiM+=(m-goukei)*(li[i][0])
    goukei=m
print(goukeiM)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import *
from heapq import *
from fractions import gcd

sys.setrecursionlimit(10**6)

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

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

res = 0
for a in sorted(A):
    if(a[1] < M):
        M -= a[1]
        res += a[0] * a[1]
    else:
        res += a[0] * M
        M = 0
    if(M == 0):
        break
print(res)

exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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 (yen, num) in AB:
    if num <= M:
        ans += (yen * num)
        M -= num
    else:
        ans += (yen * M)
        print(ans)
        exit()

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
d = {}
ans = 0
for _ in range(n):
  a,b = map(int, input().split())
  if a in d:
    d[a] += b
  else:
    d[a] = b

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

for i in range(len(d)):
  if m >= d[i][1]:
    ans += d[i][0] * d[i][1]
    m -= d[i][1]
  else:
    ans += d[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.sort()
#print(AB)

cost = 0
for i in range(N):
    cost += AB[i][0] * min(AB[i][1], M)
    M = M - min(AB[i][1], M)
    if M == 0:
        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,cnt=0,0
for a,b in AB:
  for i in range(b):
    ans+=a
    cnt+=1
    if cnt>=m:
      print(ans)
      exit()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
a = 0
l = []
f = 0
N, M = map(int, input().split())
for i in range(N):
    A, B = map(int, input().split())
    l.append([A, B])
l_sorted = sorted(l, key=lambda x: x[0])
while True:
    if l_sorted[f][1] < M:
        a += l_sorted[f][1] * l_sorted[f][0]
        M -= l_sorted[f][1]
        f += 1
    else:
        a += M * l_sorted[f][0]
        break
print(a)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())
l=[[-1]*2 for i in range(N)]

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

l.sort()
sum=0
i=0
while M>0:
    num=min(M,l[i][1])
    sum+=num*l[i][0]
    M-=num
    i+=1
print(sum)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = []
for i in range(n):
  A.append(list(map(int, input().split())))
cost = 0
count = 0
A.sort(key = lambda x:x[0])
for i in range(n):
  if count == m:
    break
  elif count + A[i][1] <= m:
    cost += A[i][1] * A[i][0]
    count += A[i][1]
  else:
    while count < m:
      cost += A[i][0]
      count += 1
print(cost)

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=sorted(AB,key=lambda x: x[0])
#print(AB)

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

Submission status: Accepted

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

Submission status: Accepted

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

res = M
n = 0
cnt = 0


while(AB[n][1] < res):
    cnt += AB[n][0] * AB[n][1]
    res -= AB[n][1]
    n += 1

cnt += res * AB[n][0]

print(cnt)

Submission status: Accepted

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

num=0
pay=0
for a,b in A:
	if num+b>=M:
		pay+=(M-num)*a
		break
	else:
		pay+=a*b
		num+=b

print(pay)

Submission status: Accepted

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

l = [[int(i) for i in input().split()] for _ in range(n)]

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


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

Submission status: Accepted

Solution code:
import sys
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(0,N):
  A[i],B[i]=map(int,input().split())
index=sorted(range(len(A)), key=lambda k: A[k])
cost=0
get=0
for i in index:
  if get+B[i]<M:
    get += B[i]
    cost += A[i]*B[i]
  else:
    cost += A[i]*(M-get)
    print(cost)
    sys.exit()

Submission status: Accepted

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

res = M
total_p = 0
for i in range(N):
    a, b = map(int, input().split())
    p_list.append(a)
    p_list.append(b)

for price, amount in sorted(zip(p_list[::2], p_list[1::2])):
    total_p += price * min(res, amount)
    res -= amount
    if res <= 0:
        break
        
print(total_p)

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
ab = np.array([list(map(int, input().split())) for _ in range(N)])

acou = 0
co_m = M
ab_s = ab[np.argsort(ab[:,0])]

for i in range(N):
    acou += ab_s[i][0] * min(co_m, ab_s[i][1])
    co_m -= min(co_m, ab_s[i][1])
    if co_m == 0:
        break

print(acou)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left
from math import factorial


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n, m = LI()
ret = 0
que = deque(sorted(LIR(n)))
while m>0:
    a, b = que.popleft()
    ret += min(m, b) * a
    m -= b



print(ret)

Submission status: Accepted

Solution code:
#!/anaconda3/bin/python
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)

Submission status: Accepted

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

Submission status: Accepted

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

c = sorted(ab, key= lambda x:x[0])
s = [0]
for i in range(n):
    s.append(s[i] + c[i][1])
    if s[i] <= m <= s[i+1]:
        stop = i

ans=0
for i in range(stop):
    ans += c[i][0]*c[i][1]
while s[stop] < m:
    ans += c[stop][0]
    s[stop] += 1
print(ans)

Submission status: Accepted

Solution code:
n,m,*l=map(int,open(0).read().split())
ans=0
for s,t in sorted(zip(l[::2],l[1::2])):
    ans+=s*min(m,t)
    m-=t
    if m<=0:
        print(ans)
        break

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M = map(int, input().split())
    
    AB = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    pay = 0

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

Submission status: Accepted

Solution code:
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
a=sorted([list(map(int,input().split())) for _ in range(n)])
#print(a)
cnt,can=0,0
for i in range(n):
    if can+a[i][1]<m:
        cnt+=a[i][0]*a[i][1]
        can+=a[i][1]
    else:
        cnt+=a[i][0]*(m-can)
        break
    #print(cnt)
print(cnt)

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
p = []

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

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

money = 0
now = 0

for p_ in p:
    price = p_[0]
    amount = p_[1]
    if now + amount < M:
        now += amount
        money += price * amount
    else:
        money += price * (M-now)
        print(money)
        sys.exit()

Submission status: Accepted

Solution code:
# -*-coding: utf-8 -*-
N, M = map(int, input().split())

ab = [0] * N 
for i in range(N):
    ab[i] = list(map(int, input().split()))

ab = sorted(ab)
honsu = 0
money = 0
flag = False
for i in range(N):
    if flag:
        break
    count = ab[i][1]
    for k in range(count):
        if honsu == M:
            flag = True
            break
        else:
            money += ab[i][0]
            honsu += 1
print(money)

Submission status: Accepted

Solution code:

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

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

AB = []

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

AB.sort()

total = 0
yen = 0
i = 0
while True:
	A = AB[i][0]
	B = AB[i][1]
	if total + B < M:
		yen += A*B
		total += B
		i += 1
	else:
		yen += (M - total)*A
		break
print(yen)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
dct = {}
for _ in range(n):
    a,b = map(int,input().split())
    if a in dct:
        dct[a] += b
    else:
        dct[a] = b
dct = sorted(dct.items())
ans,tmp = 0,0
for a,b in dct:
    for _ in range(b):
        if tmp < m:
            ans += a
            tmp += 1
        else:
            print(ans)
            exit()
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.keys():
    d[a] = d[a] + b
  else:
    d[a] = b

ans = 0
getDrink = 0
keys_sorted = sorted(d.keys())
isFinish = False
for key in keys_sorted:
  if isFinish:
    break
  for i in range(d[key]):
    getDrink += 1
    ans += key
    if getDrink == m:
      isFinish = True
      break
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(key = lambda x: x[0])
res = 0
#print(a)
for i in range(N):
  if M - a[i][1] < 0:
    res += a[i][0] * M
    break
  else:
    res += a[i][1] * a[i][0]
    M -= a[i][1]
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ab=[]
cost=0
cnt=0
for i in range(n):
  ab.append(list(map(int,input().split())))
ab=sorted(ab)
#print(ab)
j=0
while m>0:
  if m>ab[j][1]:
    cost+=ab[j][0]*ab[j][1]
    m-=ab[j][1]
  else:
    cost+=m*ab[j][0]
    m=0
  j+=1
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(key = lambda x:x[0])
ans = 0
for i in range(n):
  while ab[i][1] > 0 and m> 0:
    m -= 1
    ab[i][1] -= 1
    ans += ab[i][0]
    
print(ans)

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

ab = sorted(ab)
count = 0
total = 0
idx = 0
while True:
    if count >= m:
        total -= (count-m) * ab[idx-1][0]
        break
    total += ab[idx][0] * ab[idx][1]
    count += ab[idx][1]
    idx += 1

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

p = 0
s = 0
i = 0
while s < m:
    a, b = ls[i]
    if s + b < m:
        s += b
        p += b * a
    else:
        p += (m - s) * a
        break
    i += 1
print(p)

Submission status: Accepted

Solution code:
import sys

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

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

AB.sort()

#print(AB)

total_buttle = 0
total_cost = 0
for _ in range(N):
    total_buttle = total_buttle + AB[_][1]
    if (total_buttle >= M):
        total_cost = total_cost + AB[_][0]*AB[_][1] - AB[_][0]*(total_buttle-M)
        #print(total_buttle,total_cost)
        #print(total_buttle,M)
        break

    total_cost = total_cost + AB[_][0]*AB[_][1]


print(total_cost)

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

N, M = map(int, input().split())
A = [0]*N
B = [0]*N
l = []
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
    l.append((a, b))
    
l.sort()
ans = 0
for (a, b) in l:
    if b >= M:
        ans += a * M
        break
    else:
        ans += a * b
        M -= b
print(ans)

Submission status: Accepted

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

n,m = MAP()
lst = [MAP() for _ in range(n)]
lst = sorted(lst,key = lambda x:x[0])
q = 0
ans = 0

for i in lst:
    if q+i[1]<m:
        q+=i[1]
        ans+=i[0]*i[1]
    else:
        ans += (m-q)*i[0]
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

mise.sort()

honnsuu = 0
kinngaku = 0
for a, b in mise:
    if honnsuu >= M:
        break

    kauhonnsuu = M - honnsuu
    kaeruhonnsuu = min(kauhonnsuu, b)
    kinngaku += kaeruhonnsuu * a
    honnsuu += kaeruhonnsuu

print(kinngaku)

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()
money=0
for i in range(n):
    if lis[i][1]<=m:
        m-=lis[i][1]
        money+=(lis[i][0]*lis[i][1])
    else:
        money+=(m*lis[i][0])
        m=0
    if m==0:
        break

print(money)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)


def main():
    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
    i = 0
    while True:
        a = AB[i][0]
        b = AB[i][1]
        logging.debug('a: %d, b: %d' % (a, b))
        while b > 0 and M > 0:
            b -= 1
            M -= 1
            ans += a
            logging.debug('b: %d, M: %d, ans: %d' % (b, M, ans))
        if M == 0:
            break
        else:
            i += 1
    return ans

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