A. Arithmetic Array

An array b of length k is called good if its arithmetic mean is equal to 1. More formally, if
b1+⋯+bkk=1.
Note that the value b1+⋯+bkk is not rounded up or down. For example, the array [1,1,1,2] has an arithmetic mean of 1.25, which is not equal to 1.

You are given an integer array a of length n. In an operation, you can append a non-negative integer to the end of the array. What’s the minimum number of operations required to make the array good?

We have a proof that it is always possible with finitely many operations.

Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.

The first line of each test case contains a single integer n (1≤n≤50) — the length of the initial array a.

The second line of each test case contains n integers a1,…,an (−104≤ai≤104), the elements of the array.

Output
For each test case, output a single integer — the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly 1.

Example
inputCopy
4
3
1 1 1
2
1 2
4
8 4 6 2
1
-2
outputCopy
0
1
16
1
Note
In the first test case, we don’t need to add any element because the arithmetic mean of the array is already 1, so the answer is 0.

In the second test case, the arithmetic mean is not 1 initially so we need to add at least one more number. If we add 0 then the arithmetic mean of the whole array becomes 1, so the answer is 1.

In the third test case, the minimum number of elements that need to be added is 16 since only non-negative integers can be added.

In the fourth test case, we can add a single integer 4. The arithmetic mean becomes −2+42 which is equal to 1.

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e9+5;
int t,n,x;
signed main(){cin >> t;while (t--){cin>>n;int sum=0;for(int i=0;i<n;++i){cin>>x;sum+=x;}if(sum<n) cout<<1<<'\n';if(sum==n) cout<<0<<'\n';if(sum>n) cout<<sum-n<<'\n';}}

A. Arithmetic Array Codeforces Round #726 (Div. 2)相关推荐

  1. Codeforces Round #726 (Div. 2) E2. Erase and Extend (Hard Version) 贪心

    传送门 文章目录 题意: 思路: 题意: 给你一个长度为nnn的串sss,你有两个操作可以使用: (1)(1)(1)从sss的结尾删除一个字母. (2)s=s+s(2)s=s+s(2)s=s+s. 让 ...

  2. Codeforces Round #726 (Div. 2) F. Figure Fixing 二分图 + 思维

    传送门 文章目录 题意: 思路 题意: 给你一张nnn个点mmm条边的图,每个点都有一个当前值aia_iai​,目标值bib_ibi​,每次可以选择一条边(i,j)(i,j)(i,j),将ai,aja ...

  3. Codeforces Round #726 (Div. 2) D. Deleting Divisors 博弈

    传送门 文章目录 题意: 思路: 题意: 给你一个数nnn,有两个人博弈,每次可以将nnn减去一个nnn的因子,这个因子不能为111或nnn.当不能操作的人输掉游戏.问你先手赢还是后手赢. 思路: 这 ...

  4. Codeforces Round #700 (Div. 2) D2 Painting the Array II(最通俗易懂的贪心策略讲解)看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 整场比赛的A ~ E 6题全,全部题目超高质量题解链接: Codeforces Round #700 ...

  5. 【Codeforces Round #767 (Div. 2)】 C. Meximum Array 题解

    [Codeforces Round #767 (Div. 2) ]C. Meximum Array 题解 1629C: Meximum Array 题解 [Codeforces Round #767 ...

  6. Codeforces Round #538 (Div. 2) F. Please, another Queries on Array? 线段树 + 欧拉函数

    传送门 文章目录 题意: 思路: 题意: 给你一个序列aaa,你需要实现两种操作: (1)(1)(1) 将[l,r][l,r][l,r]的aia_iai​都乘rrr. (2)(2)(2) 求ϕ(∏i= ...

  7. Codeforces Round #727 (Div. 2) F. Strange Array 线段树 + 区间合并 + 排序优化

    传送门 文章目录 题意: 思路: 题意: 给你一个长度为nnn的数组,对每个位置iii求一个最大价值,价值计算方式如下:选择一个包含iii的[l,r][l,r][l,r],让后将其拿出来排序,之后价值 ...

  8. Codeforces Round #632 (Div. 2) C. Eugene and an array 思维 + 前缀和

    传送门 文章目录 题意: 思路: 题意: 给定一个长度为nnn的序列aaa,定义一段区间为好区间是这段区间的所有连续子区间的和都不为000,求好区间的个数. 思路: 套路题,定义aia_iai​的前缀 ...

  9. Codeforces Round #538 (Div. 2) (CF1114)

    Codeforces Round #538 (Div. 2) (CF1114)   今天昨天晚上的cf打的非常惨(仅代表淮中最低水平   先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O( ...

最新文章

  1. 可视化生信分析利器 Galaxy 之 Docker 部署
  2. numpy python2_python-numpy(2)
  3. Flink的处理背压​原理及问题-面试必备
  4. mysql s授权所有用户_批量获取mysql用户权限的方法
  5. 判断字符串格式_Python基础教程,第四讲,字符串详解
  6. Azkaban的编译与安装
  7. 禁用”mgmtdb实例导致12c 应用psu失败
  8. PS图片删除需要计算机管理权限,电脑打开ps,显示没有管理员权限
  9. 测试点击屏幕次数的软件_显示器响应时间测试软件
  10. 多曝光HDR成像 跑出来的图片颜色变绿
  11. 云计算与大数据——数据挖掘常用算法
  12. ecshop二次开发手册【基本结构】
  13. 2020年最好用的离线下载网盘,不限速度和空间
  14. 幻数java题_java – 公式中的幻数
  15. 网易云静态页面html+css-----首页、热歌榜、搜索
  16. 爱奇艺迎史上最大裁员潮:总监说撸就撸,有的部门直接裁一半......
  17. 在微软Win10系统下安装SQL Server 2005时提示无法启动服务
  18. SQL多表联合查询(交叉连接,内连接,外连接)
  19. 转载:linux drm原理及应用
  20. 电商收付通可视化进件二级商户,多功能升级

热门文章

  1. java 抽象类语法_JAVA基础语法8--多态/抽象类/抽象方法
  2. 地贝扫地机器人维修_扫地机器人常见故障及维修方法
  3. 百度OCR文字识别-Android安全校验
  4. android Module之间数据传递
  5. android 后台执行js,android - 当应用程序在后台运行时,Android WebView消耗大量电能...
  6. java验证码限流_Java实现系统限流
  7. encapsulation java_Java - 封装(Encapsulation)
  8. 【离散数学中的数据结构与算法】五 排列与组合一
  9. 【Makefile由浅入深完全学习记录6】Makefile中变量的高级主题上
  10. Linux监控工具介绍系列——smem