Apply Aliens Trick twice. Add penalty per Poke Ball and per Ultra Ball. For each Pokemon , compute the best action among: use neither, use Poke Ball only (), use Ultra Ball only (), use both ().
Binary search on to use exactly Poke Balls. Inside that, binary search on to use exactly Ultra Balls. Total: .