I was solving SALARY and except for coming up with naive brute-force method, I couldn’t figure out the logic behind this problem. It was only after seeing the editorial I understood the logic. So, My question is how to come up with solutions to such problems. Because it was just some AP or formula.
At least this question was, more or less maths and intuition. There is no other way of training intuition except practice. You will this that this isnt the only question using that concept, there are many, many more in the market based on it.
What happens is, most of people get stuck while practicing on the first type of taht question, absorb the concept and use it later to tackle all problems of that type. And the top coders among them, absorb the concept and train their intuition to see where else it might help. Keep practicing, you will get how to come up with those.
(You can use tag feature to search for ad-hoc problems as well.)