I still got good grades back in the day because I worked hard. I ground problems until things made sense. Every problem you do adds to your problem solving toolbelt. As your toolbelt grows, you start noticing patterns and you can apply those tools to these new problems. I rarely have to derive things from first principles because I've seen so many different problems at this point.
Some people think that I'm unusually smart or have a natural aptitude for these things. That can't be further from the truth - I don't think this comes naturally to most people. You just work at it until you get good at it.
The best textbook I've found for Algorithms is the one used at Princeton: Sedgewick's "Algorithms." It's extremely practical and doesn't go into too much of the math/proofs behind the algorithms themselves. From there, just grind problems until it makes sense.