CF1316A.Grade Allocation

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

nn students are taking an exam. The highest possible score at this exam is mm. Let aia_{i} be the score of the ii-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≤m0 \leq a_{i} \leq m
  • The average score of the class doesn't change.

You are student 11 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.

有 nn 名学生参加一场考试,该考试的最高可能得分为 mm。设第 ii 名学生的得分为 aia_{i}。你可以访问学校数据库,其中存储了所有学生的成绩。

在满足以下条件的前提下,你可以修改每名学生的成绩:

  • 所有成绩均为整数;
  • 0≤ai≤m0 \leq a_{i} \leq m;
  • 班级的平均分保持不变。

你是第 11 号学生,希望最大化自己的成绩。

求在满足所有条件的情况下,你能为自己分配的最高可能得分。

输入格式

Each test contains multiple test cases.

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

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

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

每个测试包含多个测试用例。

第一行包含测试用例的数量 tt(1≤t≤2001 \le t \le 200)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤1031 \leq n \leq 10^{3},1≤m≤1051 \leq m \leq 10^{5})—— 分别表示学生人数和可能的最高分。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n($ 0 \leq a_{i} \leq m$)—— 表示各位学生的得分。

输出格式

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.52.5. You can change array aa to [10,0,0,0][10,0,0,0]. Average remains 2.52.5, and all conditions are satisfied.

In the second case, 0≤ai≤50 \leq a_{i} \leq 5. You can change aa to [5,1,1,3][5,1,1,3]. You cannot increase a1a_{1} further as it will violate condition 0≤ai≤m0\le a_i\le m.

第一种情况中,a=[1,2,3,4]a = [1,2,3,4],其平均值为 2.52.5。你可以将数组 aa 修改为 [10,0,0,0][10,0,0,0],平均值仍为 2.52.5,且所有条件均满足。

第二种情况中,0≤ai≤50 \leq a_{i} \leq 5。你可以将 aa 修改为 [5,1,1,3][5,1,1,3]。你不能再增大 a1a_{1},否则将违反条件 0≤ai≤m0\le a_i\le m。

输入解题思路,AI测评打分。不知道怎么写?

首页