I am not sure if you read the hidden portion. Anyway, here's the approach:
Consider the ak students who gave wrong answers to at least k questions. Since they could not have got more than k questions wrong (as per the 2nd sentence of the problem), this means ak students gave exactly k wrong answers contributing kak to the tally of wrong answers.
Now ak-1 students gave at least k-1 wrong answers - this group will comprise of those who have exactly (k-1) wrongs and those who have exactly k wrongs. Its obvious therefore that the number of students with exactly (k-1) wrongs is (ak-1-ak) so now we have a contribution of (k-1)(ak-1-ak).
Add 'em up and you will get a1+a2+...+ak