#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); const long long INF = (long long)1e18 + 1; int n, k; long long p; cin >> n >> p >> k; vector t(n), b(n); for (int i = 0; i < n; i++) { cin >> t[i] >> b[i]; } vector> dp(n + 1, vector(k + 1)); dp[0][0] = p; for (int i = 0; i < n; i++) { for (int j = 0; j <= min(i, k); j++) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j < k) { long long p_new = dp[i][j]; if (t[i] == 1) { p_new += b[i]; } else { p_new *= 2; } p_new = min(p_new, INF); dp[i + 1][j + 1] = max(dp[i + 1][j + 1], p_new); } } } if (dp[n][k] == INF) { cout << -1 << endl; } else { cout << dp[n][k] << endl; } }