Comments

The maxsum state is pretty much sparse, and you could use map . so the state will be [N][K][max_sum] , use negative or something to define if max_sum isn't choosed yet.

+1

I also had wrong answer in test 24. I realized this after the contest finished :/. you can't do binary search. try this case 10 1110000011

my program runs correctly for such tc ._.

keep getting wa on pretest 7 ...