Solving "building and two glass balls" task with dynamic programming