CF1316A.Grade Allocation
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
n students are taking an exam. The highest possible score at this exam is m . Let ai be the score of the i -th student. You have access to the school database which stores the results of all students.
You can change each student's score as long as the following conditions are satisfied:
- All scores are integers
- 0≤ai≤m
- The average score of the class doesn't change.
You are student 1 and you would like to maximize your own score.
Find the highest possible score you can assign to yourself such that all conditions are satisfied.
输入格式
Each test contains multiple test cases.
The first line contains the number of test cases t ( 1≤t≤200 ). The description of the test cases follows.
The first line of each test case contains two integers n and m ( 1≤n≤103 , 1≤m≤105 ) — the number of students and the highest possible score respectively.
The second line of each testcase contains n integers a1,a2,…,an ( $ 0 \leq a_{i} \leq m$ ) — scores of the students.
输出格式
For each testcase, output one integer — the highest possible score you can assign to yourself such that both conditions are satisfied._
输入输出样例
输入#1
2 4 10 1 2 3 4 4 5 1 2 3 4
输出#1
10 5
说明/提示
In the first case, $a = [1,2,3,4] $ , with average of 2.5 . You can change array a to [10,0,0,0] . Average remains 2.5 , and all conditions are satisfied.
In the second case, 0≤ai≤5 . You can change a to [5,1,1,3] . You cannot increase a1 further as it will violate condition 0≤ai≤m .