I am doing a spreadsheet for student grades. There is a limit (30% of no of students) on how many students can get A or A+.

More students get A's based on their test scores than is allowed, so I want to know if there is a formula (to put in Column D2 below) to automatically reduce the A scores of the students over the 30% limit down to B+

Example

There are 20 students in a class but only 6 can get A and above.

However 8 get A scores on their tests.

So I need a formula to reduce the two lowest A scores outside of the 30% range to B+.