Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — 4.54.5 would be rounded up to 55 (as in example 3), but 4.44.4 would be rounded down to 44.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than 55(maybe even the dreaded 22). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get 55 for the course. Of course, Vasya will get 55 for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
The first line contains a single integer nn — the number of Vasya's grades (1≤n≤1001≤n≤100).
The second line contains nn integers from 22 to 55 — Vasya's grades for his lab works.
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a 55.
3 4 4 4
2
4 5 4 5 5
0
4 5 3 3 5
1
In the first sample, it is enough to redo two lab works to make two 44s into 55s.
In the second sample, Vasya's average is already 4.754.75 so he doesn't have to redo anything to get a 55.
In the second sample Vasya has to redo one lab work to get rid of one of the 33s, that will make the average exactly 4.54.5 so the final grade would be 55
.
最少改动几个数 可以使平均值为5
贪心
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int m[200];
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> m[i];
sum += m[i];
}
sort(m, m + n);
int res = 0;
for (int i = 0; i < n; i++) {
double t = (double)sum / (double)n;
if (t >=4.50)
break;
sum += 5 - m[i];
m[i] = 5;
res++;
}
cout << res<<endl;
}