3819 ACM/ICPC Asian semi-finals Mudanjiang site competition-A (zoj) 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 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
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional Contest


Link: average score


Solution: sign-in questions from Mudanjiang station !!! It was so disgusting. At the scene, it seemed like it was just an hour before I had a question. It was too good... At first, I did not think of a simple method. I wanted to enumerate brute force, and then I thought about how to calculate the average scores of N-1 individuals in Class A, and then take the lower bound. This is the maximum score, calculate the average score of m people in Class B and take the upper bound. This is the lower bound of the score.



AC code:

# Include <stdio. h> # include <string. h> # include <iostream> # include <algorithm> # include <vector> # include <queue> # include <set> # include <map> # include <string> # include <math. h> # include <stdlib. h> # include <time. h> using namespace STD; # define INF 0x7fffffint main () {# ifdef sxk freopen ("in.txt", "r", stdin); # endif int t, n, m, sum, C; scanf ("% d", & T); While (t --) {sum = 0; scanf ("% d", & N, & M); For (INT I = 0; I <n-1; I ++) {scanf ("% d", & C); sum + = C ;} double ans1 = 1.0 * sum/(n-1); If (floor (ans1) = ans1) ans1 --; else ans1 = floor (ans1); // sum = 0; for (INT I = 0; I <m; I ++) {scanf ("% d", & C); sum + = C ;} double ans2 = 1.0 * sum/m; If (floor (ans2) = ans2) ans2 ++; // obtain the upper bound else ans2 = Ceil (ans2 ); cout <ans2 <"" <ans1 <Endl;} return 0 ;}





3819 ACM/ICPC Asian semi-finals Mudanjiang site competition-A (zoj) 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.