Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
prise = []
conte = []
suma = 0
sum_p = 0
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    suma += a*b
    sum_p += b

while sum_p >= m:
    ind = prise.index(max(prise))
    if conte[ind] >= (sum_p - m):
        suma = suma - (sum_p-m)*prise[ind]
        break
    else:
        suma = suma - conte[ind]*prise[ind]
        sum_p -= conte[ind]
        if sum_p == m:
            break
    prise.pop(ind)
    conte.pop(ind)
print(suma)

Fixed submission:
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
for p in range(n):
    ind = prise.index(min(prise))
    cost += min(prise) * conte[ind]
    ki += conte[ind]
    temp = min(prise)
    conte.pop(ind)
    prise.pop(ind)
    
    if ki >= m:
        if ki-m > 0:
            cost = cost - (ki-m)*temp
        break
    
print(cost)

Fixed submission:
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
while ki <= m:
    ind = prise.index(min(prise))
    cost += min(prise) * conte[ind]
    ki += conte[ind]
    temp = min(prise)
    conte.pop(ind)
    prise.pop(ind)
    
    if ki >= m:
        if ki-m > 0:
            cost = cost - (ki-m)*temp
        break
    
print(cost)

Fixed submission:
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
prise = []
conte = []
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    
ki = 0
cost = 0
while ki <= m:
    ind = prise.index(min(prise))
    for p in range(conte[ind]):
        cost += min(prise)
        ki += 1
        if ki >= m:
            break
    prise.pop(ind)
    conte.pop(ind)
    if prise == []:
        break
    if ki == m:
        break
print(cost)

Fixed submission:
n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)