calculate upperbound follow algorithm