492C is relatively easy. But we should not ignore the exceed time limit problem.
I use heap to complete this task. pop out a element each time. We should notice that it is a bad idea to increase the sum every time one by one, which may result in time limit exceed. We should split it as two problems.
The source code is as follows:
import heapq
n, r, avg = map(int, raw_input().split())
h = []
h1 = []
for i in xrange(n):
temp = list(map(int, raw_input().split()))
if r - temp[0] > 0:
heapq.heappush(h, [temp[1], r - temp[0]])
h1.append(temp[0])
h.sort()
h.reverse()
s = sum(h1)
x = n * avg - s
ans = 0
while x > 0 :
temp = h.pop()
if temp[1] > x :
ans += temp[0] * x
x = 0
else :
x -= temp[1]
ans += temp[0] * temp[1]
print ans