A13332 | Grade Allocation
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
$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.
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.
输入格式
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.
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.
输出格式
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 \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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted