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: Time Limit Exceeded

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

#%%

# print(n, m, ab)
# n, m, ab = 4, 30, [[6, 18], [2, 5], [3, 10], [7, 9]]


#%%
ab.sort()

#%%
ans = 0
num = 0
while num < m:
    a0 = ab[0][0]
    b0 = ab[0][1]
    if b0 >= m - num:
        ans += a0 * (m - num)
        break
    else:
        ans += a0 * b0
        num += b0
        ab.remove([a0, b0])
#%%
print(ans)
#%%

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
x = []
y = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
ans = 0

while(1):
    if m == 0:
        break
    if y[x.index(min(x))] <= m:
        tmp = x.index(min(x))
        ans += min(x)*y[x.index(min(x))]
        m -= y[x.index(min(x))]
        x.pop(tmp)
        y.pop(tmp)
    else:
        ans += min(x)*m
        m = 0
print(ans)

Submission status: Time Limit Exceeded

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

remain_drink = M
price = 0
while remain_drink > 0:
    min_ind = -1
    min_price = 10 ** 10
    for i in range(N):
        if AB[i][0] < min_price:
            min_price = AB[i][0]
            min_ind = i

    if AB[min_ind][1] <= remain_drink:
        price += AB[min_ind][0] * AB[min_ind][1]
        remain_drink -= AB[min_ind][1]
    else:
        price += AB[min_ind][0] * remain_drink
        remain_drink = 0
    AB[min_ind][0] = 10 ** 10

print(price)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
INF = 10**9
A = []
B = []

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

ans = 0
count = 0
while(count < M):
  min_A = min(A)
  min_Ai = A.index(min_A)
  B_min = B[min_Ai]
  if count + B_min > M:
    ans += min_A * (M - count)
    count = M
  else:
    ans += min_A * B_min
    count += B_min
  del A[min_Ai]
  del B[min_Ai]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
A = []
B = []
ans = 0
for n in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
while(m > 0):
    minA = min(A)
    if B[A.index(minA)] >= m:
        ans += minA*m
    else:
        ans += minA*B[A.index(minA)]
    m = m - B[A.index(minA)]
    
    B.pop(A.index(minA))
    A.pop(A.index(minA))
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
A = []
B = []
count = 0
sum = 0

for i in range(N):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
 
while(count < M):
  min_price = min(A)
  min_index = A.index(min_price)
  A_buy_num = B[min_index]
  if((count + A_buy_num)  <= M):
   count += A_buy_num
   sum += (A.pop(min_index))*(B.pop(min_index))
  else: #(count + A_buy_num)  > M
   rest_num = M - count 
   count += rest_num
   sum += (A.pop(min_index))*(rest_num)
   break

print(sum)

Submission status: Time Limit Exceeded

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

cur = 0
cur_v = 0
for a, b in shop:
    for i in range(b):
        cur += 1
        cur_v += a
        if cur == M:
            print(cur_v)
            break

Submission status: Time Limit Exceeded

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

loop=True
pay=0

while loop:
    mise=yen.index(min(yen))
    value=yen[mise]
    stock=hon[mise]
    if M>stock:
        pay+=stock*value
    else:
        pay+=M*value
    M-=stock
    del yen[mise]
    del hon[mise]

    if M<=0:
        loop=False

print(pay)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(n):
    a,b=map(int,input().split())
    for j in range(b):lst.append(a)
lst.sort()
print(sum(lst[:m]))

Submission status: Time Limit Exceeded

Solution code:
p = input().split()
n, m = int(p[0]), int(p[1])
s = 0
k = []
h = []
for i in range(n):
    l = input().split()
    k.append(int(l[0]))
    h.append(int(l[1]))
while m > 0:
    a = min(k)
    b = h[k.index(a)]
    if m >= b:
        m -= b
        s += a*b
    else:
        s += a*m
        m = 0
    k.remove(k[k.index(a)])
    h.remove(h[h.index(b)])
print(s)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = []
B = []
sumcost = 0
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
k = 0
while k < M:
    min_index = A.index(min(A))
    B[min_index] -= 1
    sumcost += A[min_index]
    if B[min_index]<1:
        del A[min_index]
        del B[min_index]
    k += 1



print(sumcost)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
INF = 10**9
A = []
B = []

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

ans = 0
count = 0
while(count < M):
  min_A = min(A)
  min_Ai = A.index(min_A)
  if count + B[min_Ai] > M:
    ans += min_A * (M - count)
    count = M
  else:
    ans += min_A * B[min_Ai]
    count += B[min_Ai]
  del A[min_Ai]
  del B[min_Ai]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
[n,m] = [int(i) for i in input().split()]
dic = {}
for i in range(n):
    [ai,bi] = [int(i) for i in input().split()]
    if ai in dic.keys():
        dic[ai] += bi
    else:
        dic[ai] = bi
sum = 0
while m > 0:
    #print(dic)
    if dic[min(dic.keys())] >= m:
        sum += min(dic.keys()) * m
        m = 0
    else:
        sum += dic[min(dic.keys())]*min(dic.keys())
        m -= dic.pop(min(dic.keys()))
print(sum)

Submission status: Time Limit Exceeded

Solution code:

N, M = map(int, input().split())
A = [];
B = [];

for i in range(N):
    Aap, Bap = map(int, input().split())
    A.append(Aap);
    B.append(Bap);

cost = 0;

while(M>0):
    lowestPrice = min(A);
    num = A.index(lowestPrice);
    if (B[num] >= M):
        cost += M*lowestPrice;
        M = 0;
    else:
        cost += B[num]*lowestPrice;
        M -= B[num];
        del A[num];
        del B[num];

print(cost);

Submission status: Time Limit Exceeded

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

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]

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

ans = 0
need = m

while a != []:
    minprice = a.index(min(a))
    if b[minprice] >= need:
#        print('a')
        ans += a[minprice] * need
#        print(ans)
        break
    
    else:
#        print('b')
        ans += a[minprice] * b[minprice]
        need -= b[minprice]
        del a[minprice]
        del b[minprice]

#    print(ans)
        
    

print(ans)

Submission status: Time Limit Exceeded

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

drink = []
ans = 0

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

drink.sort()

for i in range(M):
    ans += drink[i]

print(ans)

Submission status: Time Limit Exceeded

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(key=lambda x: x[0])   #値段でソート
prices = []
for p in data:
    for i in range(p[1]):
        prices.append(p[0])
print(sum(prices[:m]))

Submission status: Time Limit Exceeded

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

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

cost = 0
while m > 0:
    tv = min(a)
    ti = a.index(tv)
    if m > b[ti]:
        m = m - b[ti]
        a[ti] = 10000000000
        cost += tv * b[ti]
    else:
        a[ti] = 10000000000
        cost += tv * m
        m = 0 

print(cost)

Submission status: Time Limit Exceeded

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

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

ans = 0
count = 0
while(count < M):
  min_A = min(A)
  min_Ai = A.index(min_A)
  if count + B[min_Ai] > M:
    ans += min_A * (M - count)
    count = M
  else:
    ans += min_A * B[min_Ai]
    count += B[min_Ai]
  del A[min_Ai]
  del B[min_Ai]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())

A = []
B = []
for i in range(a):
    c, d = map(int, input().split())
    A.append(c)
    B.append(d)

ans = 0

for i in range(a*b + 1):
    j = A.index(min(A))
    if(b - B[j] >=0):
        ans += A[j] * B[j]
        b -= B[j]
        A[j] = 1000000
    else:
        ans += A[j] * b
        b = 0
    if(b == 0):
        break
    
print(ans)

Submission status: Time Limit Exceeded

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

ab.sort()
print(sum(ab[:m]))

Submission status: Time Limit Exceeded

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

money = 0	
while M > 0:
	min_price = min(A)
	min_price_amount = B[A.index(min_price)]
	if M >= min_price_amount:
		M -= min_price_amount
		money += min_price * min_price_amount
		del A[A.index(min_price)]
		del B[B.index(min_price_amount)]
	else:
		money += min_price * M
		M = 0
		
print(money)

Submission status: Time Limit Exceeded

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

ab.sort()
ans = 0
while m != 0:
    tab = ab.pop(0)
    ans += min(tab[1], m)* tab[0]
    m = max(0, m - tab[1])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())

A = []
B = []
for i in range(a):
    c, d = map(int, input().split())
    A.append(c)
    B.append(d)

ans = 0

for i in range(a*b + 1):
    j = A.index(min(A))
    ans += A[j]
    B[j] -= 1
    b -= 1
    if(b == 0):
        print(ans)
        break
    if(B[j] == 0):
        A[j] = 1000000

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split(' '))
#A = []
#B = []
Drinks = []
for i in [0]*N:
	a,b = map(int,input().split(' '))
	#A.append(a)
	#B.append(b)
	Drinks+=[a]*b
Drinks.sort()
 
print(sum(Drinks[:M]))

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

for a,b in AB:
  cost += (min(max(M,0),b))*a
  M-=b
  if M<=0:
    break
print(cost)

Submission status: Accepted

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

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

AB.sort()

for i in range(N):
  if 0 < M-drinks < AB[i][1]:
    money += (M-drinks)*AB[i][0]
    break
  elif AB[i][1] <= M-drinks:
    money += AB[i][1]*AB[i][0]
    drinks += AB[i][1]
  else:
    break
    
print(money)

Submission status: Accepted

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

sum = 0
mr = 0
ks = sorted(k)

for i in range(n):
    if ks[i][1] < (m-mr):
        sum += ks[i][0] * ks[i][1]
        mr += ks[i][1]

    else:
        sum += ks[i][0] * (m - mr)
        break

print(sum)

Submission status: Accepted

Solution code:
def solve():
    N, M = [int(i) for i in input().split()]
    D = [[int(i) for i in input().split()] for _ in range(N)]
    D.sort(key=lambda x: x[0])
    ans = 0
    for d in D:
        a, b = d
        ans += a * min(M, b)
        M -= min(M, b)
        if M == 0:
            print(ans)
            exit()

if __name__ == "__main__":
    solve()

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

Submission status: Accepted

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

Submission status: Accepted

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

ll.sort()

t = 0
cst = 0
i = 0
while t < m:
    t += ll[i][1]
    cst += ll[i][0]*ll[i][1]
    if t > m:
        cst -= ll[i][0]*(t-m)
    i += 1
print(cst)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n,m = map(int,input().split())
s = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort()
for i in s:
    if m<i[1]:
        ans += m*i[0]
        break
    else:
        ans += i[0]*i[1]
        m -= 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)])

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

Submission status: Accepted

Solution code:
def main():
    # n = int(input())
    n, m = map(int, input().split())
    # a = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

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

    cost = 0
    temp_i = 0
    ab.sort(key=lambda x: x[0])
    for i in range(n):
        cost += ab[i][0] * ab[i][1]
        m -= ab[i][1]
        if m <= 0:
            temp_i = i
            break

    if m == 0:
        print(cost)
    elif m < 0:
        cost += ab[temp_i][0] * m
        print(cost)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = map(int, input().split())
prices = [0] * n
for i in range(n):
    prices[i] = tuple(map(int, input().split()))
prices = sorted(prices)

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

Submission status: Accepted

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

def main():
    n, m = map(int, input().split())
    ab = [(0, 0)] * n
    for i in range(n):
        ab[i] = tuple(map(int, input().split()))

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

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

main()

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, m = LI()
    lst = []
    for _ in range(n):
        a, b = LI()
        lst.append([a,b])

    lst.sort()

    ans = 0
    for i in range(n):
        tem = lst[i][1]
        lst[i][1] = max(0, lst[i][1]-m)
        bought = tem-lst[i][1]
        m -= bought
        ans += lst[i][0]*bought
        if m == 0:
            break

    print(ans)   
main()

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 x:x[0])
money = 0
drink = 0
for i in range(n):
  for j in range(a[i][1]):
    drink += 1
    money += a[i][0]
    if drink == m:
      print(money)
      exit()

Submission status: Accepted

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

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

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

sum = 0
price = 0
for d in drinks:
    if sum + d[1] < M:
        sum += d[1]
        price += d[0]*d[1]
    else:
        price += d[0]*(M-sum)
        break

print(price)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b = []
ans = 0
cnt = a[1]
for i in range(a[0]):
  c = list(map(int,input().split()))
  b.append(c)
b = sorted(b)
for i in b:
  if cnt == 0:
    break
  ans += i[0]*min(cnt,i[1])
  cnt -= min(cnt,i[1])
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(N)]
AB.sort()
ans=0
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
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

N, M = map(int, input().split())
drinks = list()
for i in range(N):
  a, b = map(int,input().split())
  drinks.append((a,b))

drinks.sort(key = lambda x: x[0])
#print(drinks)
ans = 0
i = 0
while M > 0:
    a, b = drinks[i]
    i += 1
    if M <= b:
        ans += a*M
        M = 0
    else:
        ans += a*b
        M -= b
    #print(ans,M)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

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

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

drinks.sort(key = lambda x: x[0])
#print(drinks)
ans = 0
while M > 0:
    a, b = drinks.pop(0)
    if M <= b:
        ans += a*M
        M = 0
    else:
        ans += a*b
        M -= b
    #print(ans,M)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    a_b_dict = defaultdict(int)
    for _ in range(N):
        a, b = map(int, input().split())
        a_b_dict[a] += b
    ans = 0
    for a, b in sorted(a_b_dict.items()):
        if M >= b:
            M -= b
            ans += a * b
        else:
            ans += a * M
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
# row = [int(input().rstrip()) for _ in range(n)]

def resolve():
    import sys
    input = sys.stdin.readline

    n, m = [int(x) for x in input().rstrip().split(" ")]

    ab = {}
    for _ in range(n):
        a, b = [int(x) for x in input().rstrip().split(" ")]
        if a not in ab:
            ab[a] = 0
        ab[a] += b

    a_list = sorted(ab.keys())
    ans = 0
    for a in a_list:
        if m <= ab[a]:
            ans += m * a
            break
        else:
            ans += ab[a] * a
            m -= ab[a]

    print(ans)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

ab.sort()

payment = 0

for i in ab:
  price = i[0]
  amount = i[1]
  if amount > m:
    amount = m
  m -= amount
  payment += amount*price
  if m == 0:
    break

print(payment)

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 12.09.2020 18:05:06

import sys

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

ls = []

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

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

ans = 0

for l in ls:
    if l[1] <= M:
        M -= l[1]
        ans += l[0] * l[1]
    else:
        ans += l[0] * M
        break


print(ans)

Submission status: Accepted

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

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

li.sort()

g=0
s=0

for i in range(N):
    if li[i][1]+s<M:
        s+=li[i][1]
        g+=li[i][1]*li[i][0]
    else:
        g+=(M-s)*li[i][0]
        print(g)
        exit()

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()
c=0
for a,b in l:
  c+=min(b,m)*a
  m=max(m-b,0)

print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
stores = [list(map(int, input().split())) for _ in range(n)]
sorted_sotres = sorted(stores, key=lambda x: x[0])
total = 0
ans = 0
for cost, number in sorted_sotres:
    if number > m:
        ans += cost * m
        break
    elif number == m:
        ans += cost * number
        break
    else:
        ans += cost * number
    m -= number
print(ans)

Submission status: Accepted

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  

n,m=input2()
AB=[input_array() for _ in range(n)]

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

for i in range(n):
	a= AB[i][0]
	b= AB[i][1]
	if b>m:
		ans+=a*m
		break
	elif b==m:
		ans+=a*b
		break
	else:
		ans+=a*b
	m-=b
print(ans)

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, m = Input()
    data = sorted([Input() for _ in range(n)])
    amount = 0
    for x, y in data:
        get1 = min(y, m)
        m = m - get1
        amount += get1 * x
        if m <= 0:
            return amount

print(main())

Submission status: Accepted

Solution code:
n,m = map(int, input().split(" "))
a = sorted(list(map(int, input().split(" "))) for i in range(n))
total = 0
for i, j in a:
  if j < m:
    m -= j
    total += i * j
  else:
    total += i * m
    break
print(total)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
for _ in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
ans=0
for a,b in l:
  ans+=min(b,m)*a
  m=max(0,m-b)
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_sorted = sorted(ab, key=lambda x:x[0])
 
num = 0
amount_of_money = 0

for i in range(n):
    buy = min(ab_sorted[i][1], m-num)
    num += buy
    amount_of_money += ab_sorted[i][0] * buy
        
    if num >= m:
        print(amount_of_money)
        exit(0)

Submission status: Accepted

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

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

num = 0
amount_of_money = 0
for i in range(n):
  buy = min(ab_sorted[i][1], m-num)
  num += buy
  amount_of_money += ab_sorted[i][0] * buy
    
  if num >= m:
    print(amount_of_money)
    exit(0)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
# print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cost)

Submission status: Accepted

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

ans = 0
cnt = 0
last_cnt = 0
for a, b in sAB:
    cnt += b
    if cnt < M:
        ans += a*b
        last_cnt = cnt
    else:
        ans += a*(M-last_cnt)
        break

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
sAB = sorted(AB, key=lambda x: x[0])

sB = [sAB[i][1] for i in range(N)]
cum_num = list(accumulate(sB))

num = 0
ans = 0
index_ = -1
for a, b in sAB:
    index_ += 1
    num += b
    if num >= M:
        break
    ans += a*b

if index_ == 0:
    ans += sAB[0][0]*M
else:
    ans += sAB[index_][0]*(M-cum_num[index_-1])

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
list = []
for _ in range(N):
  a,b = map(int,input().split())
  list.append([a,b])
list.sort()
ans = 0
for a,b in list:
  ans += min(b,M)*a
  M = max(0,M-b)
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = []
for _ in range(n):
  a,b = map(int,input().split())
  l.append([a,b])
l.sort()
ans = 0
for a,b in l:
  ans += min(b,m)*a
  m = max(0,m-b)
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lsd = []
for i in range(N):
    lsd.append(list(map(int,input().split())))
lsd.sort(key=lambda x:x[0])
ans = 0
i = 0
while M != 0:
    if M >= lsd[i][1]:
        ans += lsd[i][0]*lsd[i][1]
        M -= lsd[i][1]
    else:
        ans += lsd[i][0]*M
        M = 0
    i += 1
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
que = [getList() for i in range(N)]
que.sort(reverse = True)

left = M
ans = 0
while left > 0:
    a, b = que.pop()
    buy = min(left, b)
    left -= buy
    ans += buy * a
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()
ans = 0
for i in range(n):
    if m >= ab[i][1] :
        ans += ab[i][0]*ab[i][1]
        m = m -ab[i][1]
    elif 0 < m < ab[i][1] :
        ans += m*ab[i][0]
        break
print(ans)

Submission status: Accepted

Solution code:
n, m= map(int, input().split())
got=0
sell={}
buy=0
for i in range(n):
  a,b=map(int,input().split())
  if a not in sell:
    sell[a]=0
  sell[a]+=b
sell=sorted(sell.items())
if m<=sell[0][1]:
  print(m*(sell[0][0]))
  exit()
for lis in sell:
  got+=lis[1]
  if got>m:
    buy+=(m-got+lis[1])*lis[0]
    print(buy)
    exit()
  else:
    buy+=(lis[0])*(lis[1])

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
t=m
for i in range(n):
  if ab[i][1]<t:
    ans+=ab[i][0]*ab[i][1]
    t-=ab[i][1]
  else:
    ans+=ab[i][0]*t
    print(ans)
    exit()

Submission status: Accepted

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

    for ab in ab_list:
        a, b = ab[0], ab[1]
        if b <= m:
            ans += a * b
            m -= b
        else:
            ans += a * m
            break

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
List.sort()
res = 0
num = 0
i = 0
while num < M:
  if List[i][1] != 0:
    pass
  else:
    i +=1
  num += 1
  res += List[i][0]
  List[i][1] += -1
print(res)

Submission status: Accepted

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

AB.sort()
cost = 0
cnt = 0
i = 0
while(cnt<M):
  a, b = AB[i]
  if M-cnt<=b:
    cost += a * (M-cnt)
    cnt = M
    break
  cost += a * b
  cnt += b
  i += 1
ans = cost
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
store_m = [list(map(int, input().split())) for i in range(N)]
store = sorted(store_m)
buy = 0
cost = 0
for i in range(N):
    buy += store[i][1]
    if buy < M:
        cost += store[i][0] * store[i][1]
    else:
        cost += store[i][0] * (M - (buy - store[i][1]))
        print(cost)
        exit()

Submission status: Accepted

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

s = [tuple(map(int, input().split())) for _ in range(n)]
s.sort()

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

print(ans)