http://codeforces.me/gym/101047/problem/F
I have been trying(unsuccessfully :-( ) to solve this problem for quite some time now. This is my attempt so far.
Initially, I sort the Rajasis in ascending order of their hit points, breaking ties with ones which give greater recovery points. Then, I am doing a bottom-up DP, with two states — position, no of spells remaining. dp[pos,sp] contains the minimum strength required to kill Rajasi at position "pos" using at most "sp" spells. Finally, if there is a valid configuration for pos=0, the answer is "Y", else "N". This approach gives WA on test #2.
Please help me figure out if my approach is wrong. Thanks for your help.