#include using namespace std; using i64 = long long; #define yn(pope) (pope ? "Yes" : "No") #define rep(i, n, m) for (int i = (n); i < (m); i++) #define rrep(i, n, m) for (int i = (n); i > m; i--) #define IINF (1 << 30) #define INF (1ll << 60) #define all(v) v.begin(), v.end() int main() { int N, K; i64 P; cin >> N >> P >> K; vector dp(K + 1, 0ll); dp[0] = P; rep(_, 0, N) { int t; i64 b; cin >> t >> b; vector cp = dp; if (t == 1) { rep(i, 0, K) { cp[i + 1] = max(dp[i + 1], dp[i] + b); } } if (t == 2) { rep(i, 0, K) { cp[i + 1] = max(dp[i + 1], dp[i] << 1); } } dp = cp; rep(i, 0, K + 1) { if (dp[i] >= 1000000000000000000ll) { dp[i] = 1000000000000000000ll; } } } cout << (dp[K] > 1000000000000000000ll ? -1 : dp[K]) << endl; return 0; }