#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef unsigned long long ull; typedef long long ll; #define REP(i,n) for(int (i) = 0; (i) < (n); ++(i)) #define FOR(i,a,b) for(int (i) = a; (i) < (b); ++(i)) int t[1010]; ll b[1010]; ll f[1010][1010]; int main () { int n, k; ll p; cin >> n >> p >> k; REP(i,n) { cin >> t[i] >> b[i]; } REP(i, n) { f[i][0] = p; if (i == 0) { if (t[0] == 1) f[i][1] = p + b[0]; else f[i][1] = p * 2; f[i][1] = min(f[i][1], (ll)(1e18) + 1); continue; } FOR(j, 1, k+1) { f[i][j] = f[i-1][j]; if (f[i-1][j-1] > 0) { if (t[i] == 1) f[i][j] = max(f[i][j], f[i-1][j-1] + b[i]); else f[i][j] = max(f[i][j], f[i-1][j-1] * 2); } else continue; f[i][j] = min(f[i][j], (ll)(1e18) + 1); //cout << i << " " << j << " " << f[i][j] << endl; } } ll ans = f[n-1][k]; if (ans > (ll)1e18) ans = -1; cout << ans << endl; }