#include using namespace std; using ll = long long; #define rep(i,m,n) for(int i=m; i bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } template bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; ll P; cin >> N >> P >> K; vector T(N); vector B(N); rep(i, 0, N) cin >> T[i] >> B[i]; vector dp(N+1, vector(K+1, -1LL)); dp[0][0] = P; const ll inf1 = 1000000000000000000LL; const ll inf2 = inf1 + 100LL; rep(i, 0, N){ rep(j, 0, K+1){ if(dp[i][j] == -1LL) continue; if(j != K){ if(T[i] == 1){ if(inf1 > dp[i][j] + B[i]) chmax(dp[i+1][j+1], dp[i][j] + B[i]); else chmax(dp[i+1][j+1], inf2); }else{ if(INT_FAST16_MAX / 2LL > dp[i][j]) chmax(dp[i+1][j+1], 2LL * dp[i][j]); else chmax(dp[i+1][j+1], inf2); } } chmax(dp[i+1][j], dp[i][j]); } } cout << (dp[N][K] == inf2 ? -1 : dp[N][K]) << endl; return 0; }