Algorithm


Problem Name: 2 AD-HOC - beecrowd | 1758

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1758

Bonus Grade Points

 

By Victor Marcilio Peixoto, UNIVASF BR Brazil

Timelimit: 2

Professor Charles teaches in a school whose evalutation criteria is the following:


average ≥ 7.0 = PASS

4.0 ≤ average < 7.0 = FINAL EXAM

average < 4.0 = FAIL


Professor Charles decided to round the student grades based on their perfomance and the following rules:

1 - If the result of a rounding is lower than the original grade, the original grade will be final result.

2 - Roudings that change the student final verdict (PASS, FINAL, FAIL) are not allowed.

3 - Students that passed or are able to do the final exam will have their average replace by the highest grade obtained in the tests.

4 - Students that failed were lazy and will not receive any bonus points.

Rule 3 must be applied always when possible, as long as it does not violate rules 1 or 2.

Write a program that takes as input the grades obtained by the students in each test and calcuate their average based on the criteria stablished by Professor Charles.

 

Input

 

The first input line contains the integer T ( 1 ≤ T ≤ 5000), the number of test cases.

The first line of a test cases contains the integers P (2 ≤ P ≤ 5) and N (2 ≤ N ≤ 50), indicating the number of exams the professor applied and the number of students enrolled in the course, respectively.

The following N lines will have P floating point numbers (with 1 number after decimal point) each, indicating the grades (0.0 ≤ grade ≤ 10.0) obtained by the ith student in each of the exams.

 

Output

 

For each student print a single line containing the average obtained by him after the Professor Charles' rounding rules. The average must contain 2 digits after decimal point.

 

 

 

Input Sample Output Sample

2

3 5
3.1 7.7 0.5
0.5 5.9 5.5
0.1 8.5 9.2
9.3 4.6 8.0
5.4 3.5 0.0

5 3
9.0 10.0 6.0 6.0 6.0
10.0 5.0 5.0 5.0 5.0
10.0 5.0 5.0 4.0 0.0

3.77
3.97
5.93
9.30
2.97

10.00
6.00
5.00

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <bits/stdc++.h>

using namespace std;
int main()
{
	int cases;
	int p;
	int n;
	double soma;
	double maior;
	double nota;
	
	double v[8];
	
	
	ios_base :: sync_with_stdio(0); cin.tie(0);
	
	cout.precision(2);
	cin >> cases;
	
	while (cases--)
	{
		cin >> p >> n;
		for (int i = 0; i  <  n ; ++i)
		{
			soma = 0.0;
			
			for (int j = 0; j  <  p ; ++j)
			{
				cin >> nota;
				v[j] = nota;
				soma += nota;
			}	
			soma /= p;
			sort(v, v + p);
			
			if (soma >= 4.0)
			{
				int pos = p - 1;
				maior = v[pos];
				if (soma >= 4.0 && soma  <  7.0)
				{	
					while (pos >= 0 && maior >= 7.0)
						maior = v[pos--];
					cout << fixed << max(maior, soma) << '\n';
					
				}
				else cout << fixed << max(maior, soma) << '\n';
			}
			else
				cout << fixed << soma << '\n';
				
		}
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
3 5
3.1 7.7 0.5
0.5 5.9 5.5
0.1 8.5 9.2
9.3 4.6 8.0
5.4 3.5 0.0
5 3
9.0 10.0 6.0 6.0 6.0
10.0 5.0 5.0 5.0 5.0
10.0 5.0 5.0 4.0 0.0

Output

x
+
cmd
3.77
3.97
5.93
9.30
2.97
10.00
6.00
5.00
Advertisements

Demonstration


Previous
#1755 Beecrowd Online Judge Solution 1755 The Change Solution in C, C++, Java, Js and Python
Next
#1759 Beecrowd Online Judge Solution 1759 Ho Ho Ho Solution in C++, Java, Js and Python