n,p,k = map(int, input().split()) dp = [[0 for i in range(k + 1)] for i in range(n + 1)] dp[0][0] = p # dp[i][j] = i 番目のエンブレムまで使えて j 種類装備しているときの最大攻撃力 for i in range(n): t,b = map(int, input().split()) for j in range(k + 1): dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) if j != k: if t == 1: dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + b) else: dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] * 2) print(max(dp[n]))