#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); long long N,P,K; cin>>N>>P>>K; vector dp(K+1,0); dp[0] = P; rep(i,N){ int t; long long B; cin>>t>>B; vector ndp(K+1,0); rep(j,K+1){ ndp[j] = max(ndp[j],dp[j]); if(j+1<=K){ if(t==1)ndp[j+1] = max(ndp[j+1],dp[j] + B); else ndp[j+1] = max(ndp[j+1],dp[j] *2); } } rep(j,K+1)ndp[j] = min(ndp[j],(long long)Inf64); swap(dp,ndp); } long long ans = dp.back(); if(ans==Inf64)ans = -1; cout<