TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):

n, m = map(int, input().split())
h = dict()
for _ in range(n):
    k, v = map(int, input().split())
    h[k] = v
h = sorted(h.items(), key=lambda x: x[0])


ans = 0
for k, v in h:
    while v > 0:
        if m <= 0:
            exit()
        else:
            v -= 1
            ans += k
            m -= 1

print(ans)





n, m = map(int, input().split())
h = dict()
for _ in range(n):
    k, v = map(int, input().split())
    if k in h:
        h[k] += v
    else:
        h[k] = v
h = sorted(h.items(), key=lambda x: x[0])


ans = 0
for k, v in h:
    while v > 0:
        if m <= 0:
            print(ans)
            exit()
        else:
            v -= 1
            ans += k
            m -= 1
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
class Shop():
    def __init__(self, a, b):
        self.a = a
        self.b = b

N, M = [ int(x) for x in input().split(' ')]
shops = []
for i in range(N):
    a, b = [int(x) for x in input().split(' ')]
    shops.append(Shop(a, b))

shops.sort(key=lambda x: x.a)

cost = 0
bought = 0
for i in range(N):
    shop = shops[i]
    print(i, cost, bought, shop.a, shop.b)
    if (shop.b <= M - bought):
        cost += shop.a * shop.b
        bought += shop.b
    else:
        cost += shop.a * (M - bought)
        bought += (M - bought)
    if (bought == M):
        break

print(cost)


class Shop():
    def __init__(self, a, b):
        self.a = a
        self.b = b

N, M = [ int(x) for x in input().split(' ')]
shops = []
for i in range(N):
    a, b = [int(x) for x in input().split(' ')]
    shops.append(Shop(a, b))

shops.sort(key=lambda x: x.a)

cost = 0
bought = 0
for i in range(N):
    shop = shops[i]
    if (shop.b <= M - bought):
        cost += shop.a * shop.b
        bought += shop.b
    else:
        cost += shop.a * (M - bought)
        bought += (M - bought)
    if (bought == M):
        break

print(cost)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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[0]:
        money += ab[0] * ab[1]
        M -= ab[1]
    else:
        money += M * ab[1]
        break
print(money)

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)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import re
import numpy as np

np.seterr(over='raise')

N, M = [int(item) for item in re.split(r"\s", input())]

AB = []
for _ in range(N):
    AB.append([int(item) for item in re.split(r"\s", input())])

AB = np.array(AB)
A = AB[:, 0]
B = AB[:, 1]

print(AB)

sorted_B = B[np.argsort(A)]
sorted_A = np.sort(A)


cumB = np.cumsum(sorted_B)
index = np.argmax(cumB > M)

if N > 1:
    total = np.sum(sorted_A[:index] * sorted_B[:index])
    total = total + (M - cumB[index - 1]) * sorted_A[index]
else:
    total = M * sorted_A[0]

print(total)


import re
import numpy as np

np.seterr(over='raise')

N, M = [int(item) for item in re.split(r"\s", input())]

AB = []
for _ in range(N):
    AB.append([int(item) for item in re.split(r"\s", input())])

AB = np.array(AB)
A = AB[:, 0]
B = AB[:, 1]


sorted_B = B[np.argsort(A)]
sorted_A = np.sort(A)


cumB = np.cumsum(sorted_B)
index = np.argmax(cumB > M)

if N > 1 and index > 0:
    total = np.sum(sorted_A[:index] * sorted_B[:index])
    total = total + (M - cumB[index - 1]) * sorted_A[index]
else:
    total = M * sorted_A[0]

print(total)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

N, M = map(int, input().split())
lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]
lst.sort()    
print (lst)
count = M
yen = 0

for i in range(N):
    yen += lst[i][0] * min(count, lst[i][1])  
    count -= min(count, lst[i][1])
#    print (count)
    if count <= 0:
        print (yen)
        sys.exit()

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
drink_dict = {}
for i in range(N):
  A,B = map(int,input().split())
  if A not in drink_dict:
  	drink_dict[A] = B
  else:
    drink_dict[A] += B 
total_number = 0
total_price = 0
for price,number in drink_dict.items():
  if total_number + number >= M:
    print(total_price + (M-total_number) * price)
  else:
    total_price+=price*number
    total_number+= number

N,M = map(int,input().split())
drink_dict = {}
for i in range(N):
  A,B = map(int,input().split())
  if A not in drink_dict:
  	drink_dict[A] = B
  else:
    drink_dict[A] += B 
drink_list = sorted(drink_dict.items())
total_number = 0
total_price = 0
for i in drink_list:
  if total_number + i[1] >= M:
    print(total_price + (M-total_number) * i[0])
    break;
  else:
    total_price+=i[0]*i[1]
    total_number+= i[1]

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
import pandas as pd

n, m = map(int, input().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
df = pd.DataFrame(lines,
                  columns = ["price", "stock"],
                  dtype = float
                  )
df = df.sort_values(by="price")
price = 0
for i in range(n):
    if m - df.iloc[i]["stock"] > 0:
        price += df.iloc[i]["price"] * df.iloc[i]["stock"]
        m -= df.iloc[i]["stock"]
    else:
        price += df.iloc[i]["price"] * m
        break
print(int(price))

import sys
import numpy as np

n, m = map(float, input().split())
lines = sys.stdin.readlines()
lines = [list(map(float, line.strip().split())) for line in lines]
lines.sort()
price = 0
for line in lines:
    if m - line[1] > 0:
        price += line[0] * line[1]
        m -= line[1]
    else:
        price += line[0] * m
        break
print(int(price))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
a=[]
for i in range(0,n):
    b,c=map(int,input().split())
    a.append([b,c])
a.sort()
number=0
for i in range(0,len(a)):
    while number<m:
        number=number+a[i][1]
        l=i
print(l)
answer=0
kosu=0
for k in range(0,l+1):
    answer=answer+a[k][0]*a[k][1]
    kosu=kosu+a[k][1]
print(answer)
answer=answer+a[l+1][0]*(m-kosu)
print(answer)

n,m=map(int,input().split())
a=[]
for i in range(0,n):
  b,c=map(int.input().split())
  a.append[b,c]
a.sort()
number=0
for i in range(0,len(a)):
  while number<m:
    number=number+a[i][1]
    l=i
answer=0
kosu=0
for k in range(0,l-1):
  answer=answer+a[k][0]*a[k][1]
  kosu=kosu+a[k][1]
answer=answer+a[l][0]*(m-kosu)
print(answer)

n,m=map(int,input().split())
a=[]
for i in range(0,n):
    b,c=map(int,input().split())
    a.append([b,c])
a.sort()
number=0
for i in range(0,len(a)):
    if number<m:
        number=number+a[i][1]
        l=i
answer=0
kosu=0
for k in range(0,l):
    answer=answer+a[k][0]*a[k][1]
    kosu=kosu+a[k][1]
answer=answer+a[l][0]*(m-kosu)
print(answer)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(N)])
res = 0
for a,b in range(N):
    M -= b
    res += a*b
    if M < 0:
        res += a*M
        break
print(res)

N,M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for i in range(N)])
res = 0
for a,b in AB:
    M -= b
    res += a*b
    if M < 0:
        res += a*M
        break
print(res)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
sets = {}
costs_li=[]
limit_li=[]
bought=0
pay=0
for i in range (1,n+1):
    cost,limit=map(int,input().split())
    limit_li.append(cost)
    costs_li.append(cost)
    sets[str(cost)]=limit
costs_li.sort()
for j in range(0,n+1):
    if bought<m:
        pay=pay+costs_li[j]*sets[str(costs_li[j])]
        bought=bought+sets[str(costs_li[j])]
    elif bought>m:
        pay=pay-costs_li[j-1]*(bought-m)
        bought=m
    else:
        pay=pay
        bought=bought
    print(pay)

n,k=map(int,input().split())
li=[]
for i in range (0,n):
  li.append(list(map(int,input().split())))
li.sort()
bought=0
pay=0
t=0
while bought<k:
  pay=pay+(li[t][0])*(li[t][1])
  bought=bought+li[t][1]
  t=t+1
pay=pay-li[t-1][0]*li[t-1][1]
bought=bought-li[t-1][1]
bought_2=k-bought
pay_2=li[t-1][0]*bought_2
pay=pay+pay_2
print(pay)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
for i in range(N):
    A[i],B[i] = map(int, input().split())  

C = dict(zip(A,B))

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

ans = 0
cnt = 0

for k,v in dict(c_sorted).items():
    cnt += v
    if (cnt < M):
        ans += k*v
    else:
        ans += (M-cnt+v) * k
        break
print(ans) 

N, M = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
 
ABs.sort()
 
ans = 0
for A, B in ABs:
    ans += A * min(M, B)
    M -= min(M, B)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

def solve():
    cnt = 0
    money = 0
    for i in range(N):
        if cnt >= M:
            break
        if cnt + AB[i][1] >= M:
            money += AB[i][0] * (M - cnt)
            cnt = M   
        else:
            money += AB[i][0]*AB[i][1]
            cnt = AB[i][1]
    print(cnt)
    print(money)

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])

    solve()


import numpy as np

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

if __name__ == "__main__":
    N,M = list(map(int, input().split()))   
    AB = [list(map(int, input().split())) for _ in range(N)]
    AB.sort(key=lambda x: x[0])

    solve()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = (int(i) for i in input().split())  
e = [[int(i) for i in input().split()] for i in range(N)]

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)


N, M = (int(i) for i in input().split())  
e = sorted([[int(i) for i in input().split()] for i in range(N)])

result = 0
for x in e:
    if M > x[1]:
        M -= x[1]
        result += x[0] * x[1]
    else:
        result += x[0] * M
        break

print(result)




Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M = list(map(int,input().split()))
ab = [list(map(int,input().split())) for _ in range(N)]

print(ab)
ab.sort(key=lambda ab:(ab[0]))
print(ab)
s = 0
cnt = 0
for i in range(M):
    s += ab[cnt][0]
    if ab[cnt][1]>1:
        ab[cnt][1] -= 1
    else:
        cnt += 1
print(s)


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

ab.sort(key=lambda ab:(ab[0]))
s = 0
cnt = 0
for i in range(M):
    s += ab[cnt][0]
    if ab[cnt][1]>1:
        ab[cnt][1] -= 1
    else:
        cnt += 1
print(s)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from pprint import pprint
def main():
    N,M = map(int,input().split())
    store_l = []
    for i in range(N):
        store_l.append(tuple(map(int,input().split())))

    store_l = sorted(store_l,key=lambda x:x[0])
    pprint(store_l)
    ans = 0
    buynum = 0
    for price,maxnum in store_l:
        if(buynum+maxnum<=M):
            buynum += maxnum
            ans += maxnum*price
        else:
            ans += (M-buynum)*price
            break
    print(ans)

if __name__=="__main__":
    main()


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

    store_l = sorted(store_l,key=lambda x:x[0])
    ans = 0
    buynum = 0
    for price,maxnum in store_l:
        if(buynum+maxnum<=M):
            buynum += maxnum
            ans += maxnum*price
        else:
            ans += (M-buynum)*price
            break
    print(ans)

if __name__=="__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import heapq

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

heapq.heapify(L)

print(L)
drink = 0
yen = 0
while drink < M:
    a, b = heapq.heappop(L)
    if drink + b <= M:
        yen += a * b
        drink += b
    else:
        yen += a * (M - drink)
        break
print(yen)


import heapq

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

heapq.heapify(L)

# print(L)
drink = 0
yen = 0
while drink < M:
    a, b = heapq.heappop(L)
    if drink + b <= M:
        yen += a * b
        drink += b
    else:
        yen += a * (M - drink)
        break
print(yen)



Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
print(AB)
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
        print(tmp, ans)
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)

from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
lis = []
for _ in range(n):
  lis.append(list(map(int,input().split())))
lis.sort()
while(1):
  x,y = lis[0]
  if y >= m:
    ans += x*m
    break
  ans += x * y
  m -= y
  del(lis[0])
print(ans)

n,m=map(int,input().split())
lis = []
for _ in range(n):
  lis.append(list(map(int,input().split())))
lis.sort()
ans=0
for i in range(n):
  x,y = lis[i]
  if y >= m:
    ans += x*m
    print(ans)
    quit()
  ans += x * y
  m -= y
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cost=0
amount=m
for i in range(n):
    if amount>0:
        print('am:',amount)
        if amount > ab[i][1]:
            cost+=ab[i][0]*ab[i][1]
            amount-=ab[i][1]
        else:
            cost+=ab[i][0]*amount
            break
print(cost)


n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
cost=0
amount=m
for i in range(n):
    if amount>0:
        #print('am:',amount)
        if amount > ab[i][1]:
            cost+=ab[i][0]*ab[i][1]
            amount-=ab[i][1]
        else:
            cost+=ab[i][0]*amount
            break
print(cost)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, m = map(int, input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))

a = sorted(a, key=lambda x: x[0])
print(a)
purchase_price = 0


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)


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

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


for price, count in a:
    if count < m:
        purchase_price += price * count
        m -= count

    else:
        purchase_price += price * m
        m = 0

print(purchase_price)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

print(ABdict)
dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)


#! /usr/bin/env python3
# -*- coding: utf-8 -*-
N,M = [int(x) for x in input().split()]
ABdict = {}
for _ in range (N):
    A,B = [int(x) for x in input().split()]
    if A in ABdict.keys():
        ABdict[A] += B
    else:
        ABdict[A] = B

dct = sorted(ABdict.items())
ls = []
ans = 0
for i in dct:
    if M >= 0:
        ans += min(M,i[1])*i[0]    
        M -= i[1]  

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int, input().split(" "))

A=[]
B=[]

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

print(A)
A.sort()
print(B)

i = 0
p=0
n=0
while bought < M:
    p,n = A[i]
    price += p*B[n]
    bought += B[n]
    print("buy {} yen * {}".format(p, B[n]))
    i += 1

if bought > M:
    price -= (bought-M)*p

print(price)

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

A=[]
B=[]

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

A.sort()

i = 0
p=0
n=0
while bought < M:
    p,n = A[i]
    price += p*B[n]
    bought += B[n]
    i += 1

if bought > M:
    price -= (bought-M)*p

print(price)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int,input().split())
ab = [0]
num = m
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b])
ab.sort()
ans = 0
for i in ab:
    if i[1] >= num:
        ans += i[0]*num
        break
    else:
        ans += i[0]*i[1]
        num -= i[1]
print(ans)
        

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from operator import itemgetter
N,M = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i-1][0]*(pon - M)
    print(ans)

from operator import itemgetter
N,M = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(N)]
ls = sorted(ls,key=itemgetter(0))
ans = 0
pon = 0
for i in range(N):
    if pon < M:
        pon += ls[i][1]
        ans += ls[i][1]*ls[i][0]
    else:
        i = i-1
        break
if pon == M:
    print(ans)
else:
    ans -= ls[i][0]*(pon - M)
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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()

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

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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]
    print(ans)
while s[stop] < m:
    ans += c[stop][0]
    s[stop] += 1
print(ans)


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)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])

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

cost=0
shop=0
for j in range(M):
  if a[shop][1]==0:
    shop+=1
  else:
    a[shop][1]-=1
    cost+=a[0][0]
print(cost)

import numpy as np
N,M=[int(i) for i in input().split()]
a=[]
for j in range(N):
  a.append([int(i) for i in input().split()])
 
a.sort(key=lambda x:x[0])
 
cost=0
shop=0
for j in range(M):
  if a[shop][1]==0:
    shop+=1
  a[shop][1]-=1
  cost+=a[shop][0]
print(cost)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
a,b=map(int,input().split())
def f(x):
    if x%4==3:
        return 0
    elif x%4==0:
        return x
    else:
        base=x-x%3
        ans=base
        for s in range(1,x%3+1):
 #           print(base+s)
            ans^=(base+s)
 #           print(ans)
        return ans
print(f(a-1)^f(b))

n,m=map(int,input().split())
x=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0])
ans=0
for s,t in x:
#    print(s,t,m)
    if m>=t:
        m-=t
        ans+=s*t
    else:
        ans+=m*s
        break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int,input().split())
ab = []
for i in range(n):
	ab.append(list(map(int,input().split())))
sab = sorted(ab,key=lambda x:x[0])



n,m = map(int,input().split())
ab = []
for i in range(n):
	ab.append(list(map(int,input().split())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	print(cost,m)
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
		break
print(cost)

n,m = map(int,input().split())
ab = []
for i in range(n):
	ab.append(list(map(int,input().split())))
    
sab = sorted(ab,key=lambda x:x[0])
cost = 0
for i in sab:
	if m - i[1] > 0:
		m -= i[1]
		cost += i[0] * i[1]
	else:
		for j in range(m):
			cost += i[0]
		break
print(cost)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0

for i in range(N):
  price,honsu = map(int, input().split())
  dic[price] = honsu
dic = sorted(dic.items())  
for kakaku, number in dic:
    nokori = M-count
    count += number
    if count >= M:
      print(goukei)
      goukei += nokori*kakaku
      break
    else:
      goukei += number*kakaku
print (goukei)      
    
     
      
      

    

N, M = map(int, input().split())
dic = {}
count = 0
goukei = 0
 
for i in range(N):
  price,honsu = map(int, input().split())
  if price in dic:
    dic[price] += honsu
  else:
    dic[price] = honsu
dic = sorted(dic.items())
for kakaku, number in dic:
    nokori = M-count
    count += number
    if count >= M:
      goukei += nokori*kakaku
      break
    else:
      goukei += number*kakaku
print (goukei)   

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][0])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][0])
    sumcost += A[t][1]*buy
    k += buy
    t += 1


print(sumcost)

N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int, input().split())) for i in range(N))
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()
sumcost = 0
k = 0
for i in range(M):
    if M-k>A[0][1]:
        sumcost += A[0][0]*A[0][1]
        k -= A[0][1]
        A.pop(0)
    else:
        sumcost += A[0][0]*(M-k)
        break

print(sumcost)

N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))
A.sort()
sumcost = 0
k = 0
t = 0
while M-k>0:
    buy = min(M-k, A[t][1])
    sumcost += A[t][0]*buy
    k += buy
    t += 1


print(sumcost)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

N, M = list(map(int, input().split()))
A = np.zeros(N)   
B = np.zeros(N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

require = M
price = 0
while(require > 0):

    minidx = np.where(A == A.min())[0][0]
#    print("found idx = " + str(minidx))
    if(require >= B[minidx]):

        price = price + A[minidx] * B[minidx]
        require = require - B[minidx]
        A = np.delete(A, [minidx])
        B = np.delete(B, [minidx])
    else:

        price = price + A[minidx] * require
        require = 0

print(price)


YEN = 0
NUM = 1

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

require = M
price = 0
minidx = 0
while(require > 0):


    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:

        price = price + shop[minidx][YEN] * require
        require = 0

print(price)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, M = map(int, input().split())
A = []
B = []

a, b = map(int, input().split())

A.append(a)
B.append(b)

if N != 1:
    for n in range(N-1):
        a, b = map(int, input().split())
        swi = 0
        BSum = 0
        for j in range(len(A)):
            if BSum > M:
                swi = 1
                break
            else:
                if A[j] > a:
                    A.insert(j, a)
                    B.insert(j, b)
                    swi = 1
                    break
                elif A[j] == a:
                    B[j] += b
                    swi = 1
                    break
            BSum += b
        if swi == 0:
            A.append(a)
            B.append(b)

cntSum = 0
moneySum = 0

print(A, B)

for n in range(N):
    if cntSum + B[n] > M:
        moneySum += A[n] * (M - cntSum)
        cntSum += M - cntSum
        break
    else:
        cntSum += B[n]
        moneySum += A[n] * B[n]

print(moneySum)


n, m = map(int, input().split())
abList = [list(map(int, input().split())) for _ in range(n)]
abList.sort()
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b < abNum:
        abSum += b * a
        abNum -= b
    else:
        abSum += abNum * a
        break
print(abSum)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N,M=map(int,input().split())


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


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


m=0 
cost=0 
for i in range(N):
 
 if M-m==AB[i][1]:
     m+=AB[i][1]
     cost+=AB[i][0]*AB[i][1]
     break

 elif M-m<AB[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break
        else:
             cost=cost-AB[i][0]*j
 else:
      cost+=AB[i][0]*AB[i][1]
      m+=AB[i][1]
    
print(cost)

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


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


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


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

 elif M-m<A[i][1] :
      for j in range(AB[i][1]+1):
         cost=cost+AB[i][0]*j
         m=m+j
         if m==M:
             break

 cost+=AB[i][0]*AB[i][1]
 m+=A[i][1]
    
print(cost)

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


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


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


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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
    ans += ab[i][0]*ab[i][1]
    cnt += ab[i][1]
    i += 1
print(ans - (cnt - m)*ab[i][0])

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
    ans += ab[i][0]*ab[i][1]
    cnt += ab[i][1]
    i += 1
print(num - (cnt - m)*ab[i][0])

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
cnt = 0
i = 0
while cnt < m:
    ans += ab[i][0]*ab[i][1]
    cnt += ab[i][1]
    i += 1
print(ans - (cnt - m)*ab[i-1][0])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,m=map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
a.sort()  
i=0
cost=0
while m>0:
  if a[i][1]<m:
    cost+=a[i][0]*a[i][1]
    M-=a[i][1]
    i+=1
  else:
    cost+=a[i][0]*m
    print(cost)
    break

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

Verdicts: Runtime Error

Accepted