CodeCraft-20 (Div. 2)
A
Grade Allocation
Codeforces
800
原题
←B →
翻译中…

$n$ students are taking an exam. The highest possible score at this exam is $m$. Let $a_{i}$ 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 \leq a_{i} \leq 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.

翻译中…

Input

翻译中…

Each test contains multiple test cases.

翻译中…

The first line contains the number of test cases $t$ ($1 \le t \le 200$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 10^{3}$, $1 \leq m \leq 10^{5}$)  — the number of students and the highest possible score respectively.

翻译中…

The second line of each testcase contains $n$ integers $a_1, a_2, \dots, a_n$ ($ 0 \leq a_{i} \leq m$)  — scores of the students.

翻译中…

Output

翻译中…

For each testcase, output one integer  — the highest possible score you can assign to yourself such that both conditions are satisfied._

翻译中…

Note

翻译中…

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 \leq a_{i} \leq 5$. You can change $a$ to $[5,1,1,3]$. You cannot increase $a_{1}$ further as it will violate condition $0\le a_i\le m$.

翻译中…

样例

Input #1
2
4 10
1 2 3 4
4 5
1 2 3 4
Output #1
10
5
InputCopy OutputCopy
题目信息
题号
1316A
时间限制
1 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。