Zoj 3819 Average Score

Source: Internet
Author: User

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

Author: JIANG, Kai
Source: The acm-icpc Asia Mudanjiang regional Contest

Test instructions: There are n people in Bob's class (plus themselves), and the next class has m individuals. If Bob is not in his class, and in the next class, the average of the two shifts will increase. Now we have given Bob's class N-1 personal scores and the next class M personal scores, asking you the minimum and maximum of Bob's score.

Set Bob Score X, his class except him total score is Suma, the next class total score is sumb.

Obviously there are sum1/(N-1) >= x >= sum2/m + 1. For SUM1/(N-1) to divide can be divided into a discussion.

#include <stdio.h> #include <string.h> #include <algorithm>using namespace Std;int main () {int n,m,i,j , t,sumb;double suma;int x,y,a,b,max,min;scanf ("%d", &t), while (t--) {suma=0;sumb=0;scanf ("%d%d", &n,&m); for (i=0;i<n-1;i++) {scanf ("%d", &a); suma+=a;} suma=suma/(n-1); x= (int) (Suma), if (suma>x)    max=x;else if (suma==x)    max=x-1;for (i=0;i<m;i++) {scanf ("% D ", &b); sumb+=b;} sumb=sumb/m; min=sumb+1;printf ("%d%d\n", Min,max);} return 0;}

  

Zoj 3819 Average Score

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.