Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3819
Surface:
Average Score Time limit: 2 Seconds Memory Limit: 65536 KB
Bob is a freshman in Marjar University. He is clever and diligent. However, he is not good at math, especially in mathematical analysis.
After a mid-term exam, Bob is anxious about his grade. He went to the professor asking about the result of the exam. The professor said:
"Too bad! You made me so disappointed. "
"Hummm ... I am giving lessons to both classes. If you were in the other class, the average scores of both classes would increase. "
Now, you're given the scores of all students in the and the classes, except for the Bob ' s. Please calculate the possible range of Bob ' s score. All scores shall is integers within [0, 100].
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:
The first line contains integers N (2 <= N <=) and M (1 <= M <=) indicating the numb Er of students in Bob's class and the number of students in the other class respectively.
The next line contains N -1 integers A1 , A2 , ..., representing the scores of other AN-1 students in Bob's class .
The last line contains M integers B1 , B2 , ..., representing the scores of students in the other BM class.
Output
For each test case, the output of the integers representing the minimal possible score and the maximal possible score of Bob.
It is guaranteed, the solution always exists.
Sample Input
24 35 5 54 4 36 55 5 4 5 31 3 2 2 1
Sample Output
4 42 4
Test instructions
The student in a class to pull down the grade, in B class meeting to improve the grade, the student's achievement can get the maximum and minimum value. Because the integers are a bit special, it's good to note that the division is divisible.
Code:
#include <iostream>using namespace Std;int main () {int T,n,m,sum1,sum2,tmp,minn,maxx;cin>>t;while (t--) { sum1=sum2=0; cin>>n>>m;for (int i=1;i<n;i++) {cin>>tmp;sum1+=tmp;} for (int i=0;i<m;i++) {cin>>tmp;sum2+=tmp;} if (sum2%m==0) Minn=sum2/m+1;else minn= (1.0*sum2/m) +1;if (sum1% (n-1) ==0) maxx=sum1/(n-1) -1;else maxx=sum1/(n-1); cout <<minn<< "" <<maxx<<endl;} return 0;}
ZOJ 3819 Average score