Can anyone please explain the logic to solve this problem?

Link to problem : http://codeforces.com/contest/981/problem/D

I have tried a lot but could not crack it.

TIA.

Can anyone please explain the logic to solve this problem?

Link to problem : http://codeforces.com/contest/981/problem/D

I have tried a lot but could not crack it.

TIA.

You should think more about this problem from every angle. First, we can use high-to-low greedy to determine whether the binary high of the answer is 1, and then use a two-dimensional dp to verify the answer.

1 Like

Can you please elaborate? I din’t get it.