#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)); rep(i, N + 1) dp[i][0] = P; rep(i, N + 1) { rep(j, i) { if(j + 1 > k) break; int ii = i - 1; if(t[ii] == 1) dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + b[ii]); else dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] * 2); if(dp[i][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; }