#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} const long long INF = 1000000000000000001; int main(){ int n, k; long long p; cin >> n >> p >> k; vector dp(k + 1, -1); dp[0] = p; rep(i, n){ vector dp_old(k + 1, -1); swap(dp, dp_old); int t; long long b; cin >> t >> b; rep(from, k + 1){ if(dp_old[from] == -1) continue; chmax(dp[from], dp_old[from]); if(from < k){ long long val = dp_old[from]; if(t == 1){ val += b; chmax(dp[from + 1], min(val, INF)); } if(t == 2){ val *= 2; chmax(dp[from + 1], min(val, INF)); } } } // cout << dp; } if(dp[k] >= INF) cout << "-1\n"; else cout << dp[k] << "\n"; return 0; }