#include #define int ll using namespace std; #define rep(i,n) for(int i=0;i=0;i--) #define rng(i,c,n) for(int i=c;i #define _4ab8goq ios::sync_with_stdio(0),cin.tie(0); typedef long long ll; typedef vector vi; typedef pair pii; void print(){cout<<'\n';} template void print(const h&v,const t&...u){cout<>n>>p>>k; vec(pii) a(n); rep(i,n){ cin>>a[i].fi>>a[i].se; } const int inf=1e18; vi dp(k+1,-inf); dp[0]=p; rep(i,n){ auto [t,b]=a[i]; auto ndp=dp; rep(j,k){ if(dp[j]==-inf) continue; if(t==1){ chmax(ndp[j+1],min(inf,dp[j]+b)); }else{ chmax(ndp[j+1],min(inf,dp[j]*2)); } } dp.swap(ndp); } if(dp[k]==inf) dp[k]=-1; cout<