package main import . "fmt" import . "math/big" func main() { var n,k int p:=new(Int) Scan(&n,p,&k) dp:=make([]*Int,k+1) dp[0]=p b:=new(Int) for ;n>0;n-- { var t int Scan(&t,b) for i:=k-1;i>=0;i-- { if dp[i]==nil { continue } x:=new(Int) if t==1 { x.Add(dp[i],b) } else { x.Add(dp[i],dp[i]) } if e:=dp[i+1];e==nil||e.Cmp(x)<0 { dp[i+1]=x } } } if dp[k].Cmp(NewInt(int64(1e18)))>0 { Println(-1) } else { Println(dp[k]) } }