#include using namespace std; #include using namespace atcoder; using ll = long long; #define rep(i, n) for(int i = 0; i < n; i++) int main() { int N, k; ll P; cin >> N >> P >> k; vector t(N), b(N); rep(i, N) cin >> t[i] >> b[i]; ll ans = 0, ma = 1e18; vector> dp(N + 1, vector(k + 1)); dp[0][0] = P; rep(i, N) { rep(j, k) { if(dp[i][j] == 0) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if(t[i] == 1) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + b[i]); else dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] * 2); if(dp[i + 1][j + 1] > ma) { ans = -1; break; } } if(ans < 0) break; } if(ans < 0) { cout << -1 << endl; return 0; } rep(i, N + 1) { ans = max(ans, dp[i][k]); } cout << ans << endl; }