Buggy python submission (verdict: Runtime Error):
def main():
	N, M = map(int, input().split())
	S = {}
	for i in range(N):
		a, b = map(int, input().split())
		S[a] = b
	sorted_price_list = sorted(S)
	cost = 0
	for i in range(N):
		a = sorted_price_list[i]
		mc = S[a]
		if mc < M:
			M -= mc
			cost += a * mc
		else:
			cost += a * M
			print(cost)
			return
	return

if __name__ == '__main__':
	main()


Fixed submission:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Runtime Error):
def main():
	N, M = map(int, input().split())
	S = {}
	for i in range(N):
		a, b = map(int, input().split())
		S[a] = b
	sorted_price_list = sorted(S)
	cost = 0
	for i in range(N):
		a = sorted_price_list[i]
		mc = S[a]
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += a
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += a * mc
	return

if __name__ == '__main__':
	main()


Fixed submission:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, M = map(int, input().split())
	A = []
	B = []
	for i in range(N):
		a, b = map(int, input().split())
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		minp = min(A)
		for i in range(N):
			if A[i] == minp:
				mc = B[i]
				A[i] = 10**10
				break
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += minp
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += minp * mc
	return

if __name__ == '__main__':
	main()


Fixed submission:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, M = map(int, input().split())
	A = []
	B = []
	for i in range(N):
		a, b = map(int, input().split())
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		minp = min(A)
		for i in range(N):
			if A[i] == minp:
				mc = B[i]
				A[i] = 10**10
		if M <= mc:
			for i in range(mc):
				M -= 1
				cost += minp
				if M <= 0:
					print(cost)
					return
		else:
			M -= mc
			cost += minp * mc
	return

if __name__ == '__main__':
	main()


Fixed submission:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
	N, M = map(int, input().split())
	A = []
	B = []
	for i in range(N):
		a, b = map(int, input().split())
		A.append(a)
		B.append(b)
	cost = 0
	while True:
		mc = 0
		mp = min(A)
		for i in range(N):
			if A[i] == mp:
				mc = B[i]
				A[i] = 10**10
		for i in range(mc):
			M -= 1
			cost += mp
			if M <= 0:
				print(cost)
				return
	return

if __name__ == '__main__':
	main()


Fixed submission:
def main():
	N, M = map(int, input().split())
	S = []
	for i in range(N):
		a, b = map(int, input().split())
		S.append([a, b])
	sorted_shop_list = sorted(S, key=lambda x: x[0])
	cost = 0
	for i in sorted_shop_list:
		a = i[0]
		b = i[1]
		if b < M:
			M -= b
			cost += a * b
		else:
			cost += a * M
			break
	print(cost)
	return

if __name__ == '__main__':
	main()