ZOJ 3819 Average score (Math Mudanjiang game website)

Source: Internet
Author: User

Topic Links:

problemid=5373 ">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 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


PS:2014 ACM/ICPC Asian Regional Competition Mudanjiang (first station) ___ Registration Questions!


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 (Math Mudanjiang games website)

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.