#include #include using namespace std; using namespace atcoder; #define rep(i,a,b) for(it i=(it)(a);i<=(it)b;i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define moda 998244353LL #define modb 1000000007LL #define dai 2500000000000000000LL #define tyu 2500000000 #define sho -dai #define eps 1e-14 #define yn(x) cout<<(x ? "Yes":"No")<; using T=tuple; using mint=modint; using vi=vector; using vd=vector; using vs=vector; using vc=vector; using vb=vector; using vp=vector

; using vm=vector; using sp=set

; using ss=set; using si=set; using vvi=vector; using vvd=vector; using vvs=vector; using vvb=vector; using vvc=vector; using vvp=vector; using vvm=vector; using vsi=vector; using vsp=vector; using vvsi=vector; using vvsp=vector; using vvvi=vector; using vvvd=vector; using vvvvi=vector; const it dx[4]={0,1,0,-1}; const it dy[4]={1,0,-1,0}; int main(){ it n,p,k;cin>>n>>p>>k; vi t(n),b(n); rep(i,0,n-1)cin>>t[i]>>b[i]; vvi dp(n+1,vi(k+1,0)); dp[0][0]=p; rep(i,0,n-1) rep(j,0,k){ dp[i+1][j]=max(dp[i+1][j],dp[i][j]); if(j==k)break; if(t[i]==1)dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+b[i]); else dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]*2); if((db)(dp[i+1][j+1])>1e+18){ cout<<-1<