Zoj 3819 average score (mathematical problem Mudanjiang)

Source: Internet
Author: User

Zju math zoj Mudanjiang

Question link: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 5373


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 was anxious about his grade. He went to the specified sor asking about the result of the exam. The specified sor said:

"Too bad! You made me so disappointed ."

"Hummm... I am giving lessons to two classes. If you were in the other class, the average scores of both classes will increase ."

Now, you are given the scores of all students in the two classes, Except t for the Bob's. please calculate the possible range of Bob's score. all scores shall be integers within [0,100].

Input

There are multiple test cases. The first line of input contains an integerTIndicating the number of test cases. For each test case:

The first line contains two integersN(2 <=N<= 50) andM(1 <=M<= 50) indicating the number of students in Bob's class and the number of students in the other class respectively.

The next line containsN-1 IntegersA1,A2,..,An-1Representing the scores of other students in Bob's class.

The last line containsMIntegersB1,B2,..,BMRepresenting the scores of students in the other class.

Output

For each test case, output two integers representing the minimal possible score and the maximal possible score of Bob.

It is guaranteed that 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


PS: 2014 ACM/ICPC Asian contest Mudanjiang (first stop) ___ sign-in question!
The Code is as follows:

#include <cstdio>#include <cmath>int main(){    int t;    int n, m;    int minn, maxx;    scanf("%d",&t);    while(t--)    {        scanf("%d%d",&n,&m);        double sum1=0, sum2=0;        int a;        for(int i = 0; i < n-1; i++)        {            scanf("%d",&a);            sum1+=a;        }        for(int i = 0; i < m; i++)        {            scanf("%d",&a);            sum2+=a;        }        double avg1=(sum1/(n-1.0));        double avg2=sum2/(m*1.0);        if((int)avg1==avg1)            maxx=(int)avg1-1;        else            maxx=(int)avg1;        minn=(int)avg2+1;        printf("%d %d\n",minn,maxx);    }    return 0;}


Zoj 3819 average score (mathematical problem Mudanjiang)

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.