Here is a slightly narrower answer.
The three examples you gave (i.e. "be top of your class", "impress people with your piano playing", and "work hard to be admired") are, I think, more specifically, examples of "conceit" or "pride".
See this topic for further details: How are 'conceit' and 'identity-view' not the same? --
the answers to that topic suggest that any form of comparing yourself to others is a form of conceit.
There is, though, a sutta (the Bhikkhuni Sutta) which suggests that conceit can be useful or helpful:
This body comes into being through conceit. And yet it is by relying on conceit that conceit is to be abandoned.' Thus was it said. And in reference to what was it said? There is the case, sister, where a monk hears, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now.' The thought occurs to him, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now. Then why not me?' Then he eventually abandons conceit, having relied on conceit. 'This body comes into being through conceit. And yet it is by relying on conceit that conceit is to be abandoned.' Thus was it said, and in reference to this was it said.
So, for example, thinking that, "My teacher plays the piano better than I do -- if I practice like they did, I too can learn to play as well as they do" is a constructive, insightful form of conceit.
In summary, motives like "I want to be good" and "I want to be good (or comparable to) like they are" can be an effective motive.
What you find that motive satisfactory is a different topic; as is what you're motivated to practice; and what you consider good; and who you want to learn from, to emulate and/or to impress.
The question is how should I replace these bad motivations by more skillful ones?
So one answer is that the motivation itself isn't unskillful -- it may be effective. What may be more questionable isn't the motivation itself, but what you're motivated to do, who you're motivated to impress.
Apart from that, some of the canonical Buddhist social motivations are called the Brahmaviharas:
These four attitudes are said to be excellent or sublime because they are the right or ideal way of conduct towards living beings (sattesu samma patipatti). They provide, in fact, the answer to all situations arising from social contact.
One of these, mudita, is I think especially or at least partly intended to alleviate jealousy and competition -- if someone else is good or skillful then be happy for them.