Codeforce-CodeCraft-20 (Div. 2)-A. Grade Allocation
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.
水体没得说
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 50050
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
int a[N];
int main()
{
int t,n;
long long m;
read(t);
while(t--)
{
long long ans=0;
read(n),read(m);
rep(0,n,i)
{
read(a[i]);
ans+=a[i];
}
cout<<min(ans,m)<<endl;
}
}
Codeforce-CodeCraft-20 (Div. 2)-A. Grade Allocation的更多相关文章
- codeforce round#466(div.2) B. Our Tanya is Crying Out Loud
B. Our Tanya is Crying Out Loud time limit per test1 second memory limit per test256 megabytes input ...
- codeforce round #467(div.2)
A. Olympiad 给出n个数,让你找出有几个非零并且不重复的数 所以用stl的set //#define debug #include<stdio.h> #include<ma ...
- codeforce round#466(div.2)C. Phone Numbers
C. Phone Numbers time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- Codeforce Round #555 Div.3 D - N Problems During K Days
构造题 话说挺水的题..当时怎么就WA到自闭呢.. 先把每个位置按照最低要求填满,也就是相差1..然后从最后一位开始把剩下的数加上,直到不能加为止. #include <bits/stdc++. ...
- Codeforce Round #554 Div.2 C - Neko does Maths
数论 gcd 看到这个题其实知道应该是和(a+k)(b+k)/gcd(a+k,b+k)有关,但是之后推了半天,思路全无. 然而..有一个引理: gcd(a, b) = gcd(a, b - a) = ...
- 喵哈哈村的魔法考试 Round #20 (Div.2) 题解
题解: A 喵哈哈村的跳棋比赛 题解:其实我们要理解题意就好了,画画图看看这个题意.x<y,那么就交换:x>y,那么x=x%y. 如果我们经过很多次,或者y<=0了,那么就会无限循环 ...
- Codeforce Round #554 Div.2 D - Neko and Aki's Prank
dp 找规律 我好菜啊好菜啊,完全没有思路. 在合法的括号序列中,左括号数一定大于等于右括号数的,所以我们可以先定义平衡度为左括号数-右括号数. 然后可以发现一个惊人的规律..就是在trie同一深度上 ...
- 「日常训练」Skills(Codeforce Round #339 Div.2 D)
题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...
- 「知识学习&日常训练」莫队算法(一)(Codeforce Round #340 Div.2 E)
题意 (CodeForces 617E) 已知一个长度为\(n\)的整数数列\(a[1],a[2],-,a[n]\),给定查询参数\(l,r\),问\([l,r]\)内,有多少连续子段满足异或和等于\ ...
随机推荐
- 这些基本的 HTML5 标签你不能不知道
HTML5元素 HTML5是HTML最新的修订版本,2014年10月由万维网联盟(W3C)完成标准制定. HTML5是用来写网页的一门标记语言. 使用的时候需要在首行声明HTML,如:<!DOC ...
- 8.2 常见api:String类的使用
/* * String:字符串类 * 由多个字符组成的一串数据 * 字符串其本质是一个字符数组 * * 构造方法: * String(String original):把字符串数据封装成字符串对象 * ...
- 更快地访问stackoverflow
使用火狐浏览器,安装扩展组件 Decentraleyes, 完成 原理:由于爆栈本身并没有被墙, 但使用了google的api,而google的api是被墙的. 该组件替换了国内不能访问的api,所以 ...
- Mysql基础知识一
1.数据库的定义 数据:描述事物符号记录.(包括数字.文字.图形.图像.声音.档案记录等)以记录形式统一的格式进行存储. 广义上的数据:出现在计算机内部的一切二进制数据流都为数据 狭义上的数据:只是数 ...
- Restlet Client发送GET、POST等请求
插件下载 百度云盘 链接:https://pan.baidu.com/s/13R4s1UR5TONl2JnwTgtIYw 密码:rt02 插件安装 解压后,直接拖进浏览器中. 功能演示
- ClassLoader类加载器浅见
类加载器 类加载器,它拿到.class文件,它会把他拆成两部分,将static数据转换成方法区的数据结构,然后把他放在了方法区之中. 然后在堆里面建一个类对象(Class,它可以用来实例化对象),然后 ...
- 如何练习python?有这五个游戏,实操经验就已经够了
现在学习python的人越来越多了,但仅仅只是学习理论怎么够呢,如何练习python?已经是python初学者比较要学会的技巧了! 其实,最好的实操练习,就是玩游戏. 也许你不会信,但这五个小游戏足够 ...
- getline()和get()的使用区别
一.getline和get()的使用区别: 首先这两个函数都读取下一行输入,直到到达换行符:但是getline()函数会丢弃换行符,而get()将换行符保留在输入序列中 二.getline()函数的使 ...
- ASE课程总结 by 张葳
本期ASE课程分为两个阶段,第一阶段的personal project与第二阶段的team project,其中,第一阶段旨在锻炼我们个人的问题解决能力和编程能力,第二阶段则锻炼主要我们的管理能力,合 ...
- 引用传参与reference_wrapper
本文是<functional>系列的第3篇. 引用传参 我有一个函数: void modify(int& i) { ++i; } 因为参数类型是int&,所以函数能够修改传 ...