CodeCraft-20 (Div. 2)A.Grade Allocation

A. Grade Allocation
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.

Input
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≤ai≤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._

Example
inputCopy
2
4 10
1 2 3 4
4 5
1 2 3 4
outputCopy
10
5
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≤ai≤5. You can change a to [5,1,1,3]. You cannot increase a1 further as it will violate condition 0≤ai≤m.

题意:给出了n个人的分数,并且最高分不能超过m分,让你构造第一个人的最大分数

思路:取min(sum,m)即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define paii pair<int,int>
#define pali pair<ll,int>
#define pail pair<int,ll>
#define pall pair<ll,ll>
#define fi first
#define se second
int main()
{
   int t;cin>>t;
   while(t--){
     int n,m;cin>>n>>m;
     vector<int> a(n+1);
     int sum=0;
     for(int i=1;i<=n;i++) cin>>a[i],sum+=a[i];
      cout<<min(m,sum)<<endl;
   }
   return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我不会c语言

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值