Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

remaining = M
cost = 0
while True:
  store = stores[getCheapest()]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    bought = store[1]
    store[1] = 0
    cost += store[0] * bought
    remaining -= bought

print(cost)

Fixed submission:
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 安さ順にソート
stores.sort(key = lambda s: s[0])

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

def buy(amount):
  store = stores[getCheapest()]
  if store[1] >= amount: # もしこの店で買いきれるなら
    return store[0] * amount
  else: #買い切れないなら
    bought = store[1]
    store[1] = 0
    return store[0] * bought + buy(amount - bought)
  
print(buy(M))

Fixed submission:
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 安さ順にソート
stores.sort(key = lambda s: s[0])

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

bought = 0
money = 0
cheapest = getCheapest()

# M本買うまで繰り返す
while(bought < M):
  if (stores[cheapest][1] == 0):
    cheapest = getCheapest()
  money += stores[cheapest][0]
  stores[cheapest][1] -= 1
  bought += 1

# 最後にかかった金額を出力
print(money)

Fixed submission:
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 安さ順にソート
stores.sort(key = lambda s: s[0])

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 最も安い店を探す
def getCheapest():
  cheapest = 0
  for i in range(1, N):
    if (stores[i][0] < stores[cheapest][0] and stores[i][1] > 0):
      cheapest = i
  return cheapest

bought = 0
money = 0

# M本買うまで繰り返す
while(bought < M):
  index = getCheapest()
  money += stores[index][0]
  stores[index][1] -= 1
  bought += 1

# 最後にかかった金額を出力
print(money)

Fixed submission:
# -*- coding: utf-8 -*-

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

# A[i], B[i] はまとめてしまう
stores = [list(map(int, input().split())) for n in range(N)]

# 安さ順にソート
stores.sort(key = lambda s: s[0])

remaining = M
cost = 0

while True:
  store = stores[0]
  if store[1] >= remaining: # もしこの店で買いきれるなら
    cost += store[0] * remaining
    break
  else: #買い切れないなら
    cost += store[0] * store[1]
    remaining -= store[1]
    stores.pop(0)

print(cost)