A. Grade Allocation

A. Grade Allocation

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

nn students are taking an exam. The highest possible score at this exam is mm. Let aiai 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≤ai≤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.

Input

Each test contains multiple test cases.

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

The first line of each test case contains two integers nn and mm (1≤n≤1031≤n≤103, 1≤m≤1051≤m≤105)  — the number of students and the highest possible score respectively.

The second line of each testcase contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤m0≤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

input

Copy

2
4 10
1 2 3 4
4 5
1 2 3 4

output

Copy

10
5

Note

In the first case, a=[1,2,3,4]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≤ai≤5. You can change aa to [5,1,1,3][5,1,1,3]. You cannot increase a1a1 further as it will violate condition 0≤ai≤m0≤ai≤m.

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int n,m;
       cin>>n>>m;
       int sum=0;
       for(int i=0;i<n;i++)
       {
           int x;
           cin>>x;
           sum+=x;
       }
       if(sum>=m)
        printf("%d\n",m);
       else
        printf("%d\n",sum);
   }
    return 0;
}
发布了1266 篇原创文章 · 获赞 313 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/chen_zan_yu_/article/details/105061252
今日推荐