Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list([0] * N)   # A yen
B = list([0] * N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

require = M
price = 0
while(require > 0):
#    print("require = {}, price = {}".format(require, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    a = A.pop(minidx)
    b = B.pop(minidx)
    if(require >= b):
#        print("buy = {}, price = {}".format(b, a))
        price = price + a * b
        require = require - b
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + a * require
        require = 0

print(price)


Fixed submission:
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):
#    print("require = {}, price = {}".format(require, price))
#    print("idx = {}, num = {}, price = {}".format(minidx, shop[minidx][NUM], shop[minidx][YEN]))
    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + shop[minidx][YEN] * require
        require = 0

print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list([0] * N)   # A yen
B = list([0] * N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

bought = 0
price = 0
while(M > bought):
#    print("bought = {}, price = {}".format(bought, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    if(M - bought >= B[minidx]):
#        print("buy = {}, price = {}".format(B[minidx], A[minidx]))
        price = price + A[minidx] * B[minidx]
        bought = bought + B[minidx]
        del A[minidx]
        del B[minidx]
    elif(M - bought < B[minidx]):
#        print("buy = {}, price = {}".format(M - bought, A[minidx]))
        price = price + A[minidx] * (M - bought)
        bought = M
        break

print(price)


Fixed submission:
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):
#    print("require = {}, price = {}".format(require, price))
#    print("idx = {}, num = {}, price = {}".format(minidx, shop[minidx][NUM], shop[minidx][YEN]))
    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + shop[minidx][YEN] * require
        require = 0

print(price)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list([0] * N)   # A yen
B = list([0] * N)   # B hon
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))

bought = 0
price = 0
while(M > bought):
#    print("bought = {}, price = {}".format(bought, price))
    minidx = A.index(min(A))
#    print("found idx = " + str(minidx))
    if(M - bought >= B[minidx]):
#        print("buy = {}, price = {}".format(B[minidx], A[minidx]))
        price = price + A[minidx] * B[minidx]
        bought = bought + B[minidx]
    elif(M - bought < B[minidx]):
#        print("buy = {}, price = {}".format(M - bought, A[minidx]))
        price = price + A[minidx] * (M - bought)
        bought = M
    del A[minidx]
    del B[minidx]

print(price)


Fixed submission:
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):
#    print("require = {}, price = {}".format(require, price))
#    print("idx = {}, num = {}, price = {}".format(minidx, shop[minidx][NUM], shop[minidx][YEN]))
    if(require >= shop[minidx][NUM]):
        price = price + shop[minidx][YEN] * shop[minidx][NUM]
        require = require - shop[minidx][NUM]
        minidx = minidx + 1
    else:
#        print("buy = {}, price = {}".format(require, A[minidx]))
        price = price + shop[minidx][YEN] * require
        require = 0

print(price)