#include using namespace std; #define all(v) (v).begin(), (v).end() using ll = long long; using ld = long double; using pint = pair; using pll = pair; ll MX = 1e18; ll dp[1010][1010]; int main() { ll N, P, K; cin >> N >> P >> K; vector T(N), B(N); for (int i = 0; i < N; i++) cin >> T[i] >> B[i]; dp[0][0] = P; for (int i = 0; i < N; i++) { for (int j = 0; j <= K; j++) { ll nxt = (T[i] == 1 ? dp[i][j] + B[i] : dp[i][j] * 2); if (nxt > MX) { cout << -1 << endl; return 0; } dp[i+1][j+1] = max(dp[i][j+1], nxt); dp[i+1][j] = max(dp[i+1][j], dp[i][j]); } } cout << (dp[N][K] > MX ? -1 : dp[N][K]) << endl; }