Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
 
ab = [[int(x) for x in input().split()] for _ in range(n)]
 
ab.sort(key=lambda x: x[0])
 
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]
 
count, cost, index = 0, 0, 0

for bottle in b:
  if count + bottle < m:  
    count += bottle
    cost += a[index] * bottle
    index += 1
  else:
    cost += a[index] * (m - count)
    break

print(cost)

Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

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

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for bottle in b:
  index += 1
  if count + bottle < m:  
    count += bottle
  else:
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)

Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

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

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    break
    
total = a[index] * remainder
total += sum([a[i] * b[i] for i in range(index)])


print(total)

Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(x) for x in input().split()] for _ in range(n)]

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

temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder


total += sum([a[i] * b[i] for i in range(index)])


print(total)


Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

ab = [[int(l[0]), int(l[1])] for l in (input().split() for i in range(n))]
ab.sort()
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder


total += sum([a[i] * b[i] for i in range(index)])


print(total)


Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

ab = [[int(l[0]), int(l[1])] for l in (input().split() for i in range(n))]
ab.sort()
temp = sum(ab, [])  # 疑似Flatten
a, b = temp[0::2], temp[1::2]

count, index, remainder = 0, 0, 0

for i in range(n):
  if count + b[i] < m:  
    count += b[i]
  else:
    index = i
    remainder = m - count
    
total = a[index] * remainder
# print(a[index])
# print(remainder)
# print(total)

total += sum([a[i] * b[i] for i in range(index)])


print(total)

Fixed submission:
# cf. https://rion778.hatenablog.com/entry/2019/03/10/004006
import sys
input = sys.stdin.readline
 
N, M = [int(i) for i in input().split()]
 
plices = [[int(i) for i in input().split()] for _ in range(N)]
 
plices.sort(key = lambda x:x[0])
 
m = 0
cost = 0
 
for i in range(N):
    if m < M:
      buy = min(M - m, plices[i][1])
      cost += plices[i][0] * buy
      m += buy
    else:
      break

print(cost)