Guy-Manuel and Thomas have an array aa of nn integers [a1,a2,…,an ]. In one step they can add 11 to any element of the array. Formally, in one step they can choose any integer index ii (1≤i≤n ) and do ai:=ai+1 .

If either the sum or the product of all elements in the array is equal to zero, Guy-Manuel and Thomas do not mind to do this operation one more time.

What is the minimum number of steps they need to do to make both the sum and the product of all elements in the array different from zero? Formally, find the minimum number of steps to make a1+a2+ …… +an≠0+an≠0 and a1⋅a2⋅an≠0 .

Input

Each test contains multiple test cases.

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

The first line of each test case contains an integer nn (1≤n≤100) — the size of the array.

The second line of each test case contains nn integers a1,a2,…,an (−100≤ai≤100 ) — elements of the array .

Output

For each test case, output the minimum number of steps required to make both sum and product of all elements in the array different from zero.

Example
Input

 
4
3
2 -1 -1
4
-1 0 0 1
2
-1 2
3
0 -2 1
Output

 
1
2
0
2 水题。首先起码要满足每个数都不等于0,遍历时遇到为0的数先对其+1,同时ans++(进行了一次操作),同时sum(数列和)加上更新后的数(如果没更新就加上原数)。遍历完成后如果sum等于0的话,可以随便找一个数+1,同时ans++,这样能满足操作最少且sum不为0。最后输出ans即可。
#include <bits/stdc++.h>
using namespace std;
int t;
int main()
{
cin>>t;
while(t--)
{
int n;
cin>>n;
long long ans=;
int i;int temp; long long sum=;
for(i=;i<=n;i++)
{
scanf("%d",&temp);
if(temp==)
{
temp++;
ans++;
}
sum+=temp;
}
if(sum==)ans++;
cout<<ans<<endl;
}
}

Codeforces Round #618 (Div. 2)A. Non-zero的更多相关文章

  1. Codeforces Round #618 (Div. 2)

    题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...

  2. Codeforces Round #618 (Div. 1)C(贪心)

    把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...

  3. Codeforces Round #618 (Div. 1)B(几何,观察规律)

    观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...

  4. Codeforces Round #618 (Div. 1)A(观察规律)

    实际上函数值为x&(-y) 答案仅和第一个数字放谁有关 #define HAVE_STRUCT_TIMESPEC #include <bits/stdc++.h> using na ...

  5. Codeforces Round #618 (Div. 2)C. Anu Has a Function

    Anu has created her own function ff : f(x,y)=(x|y)−y where || denotes the bitwise OR operation. For ...

  6. Codeforces Round #618 (Div. 2) 小号上紫之路

    这一场涨了不少,题也比较偏思维,正好适合我 A. Non-zero 我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一 ...

  7. [CF百场计划]#2 Codeforces Round #618 (Div. 2)

    A. Non-zero Description: Guy-Manuel and Thomas have an array \(a\) of \(n\) integers [\(a_1, a_2, \d ...

  8. Codeforces Round #618 (Div. 2)-B. Assigning to Classes

    Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...

  9. Codeforces Round #618 (Div. 2)-Non-zero

    Guy-Manuel and Thomas have an array a of n integers [a1,a2,-,an]. In one step they can add 1 to any ...

随机推荐

  1. 项目中的process.bpmn的读-过程

    1.这次项目中遇到了process.bpmn类的封装好的类.怎么读呢?不知道,一周过去了,总算明白点. 2.首先也是从Controller开始,走进service层,比如mybatis,调用的就不是m ...

  2. SpringBoot整合Mybatis案例

    SpringBoot整合Mybatis案例 2019/7/15以实习生身份入职公司前端做Angular ,但是感觉前途迷茫,于是乎学习一下Java的框架——SpringBooot. 参照大神博客:ht ...

  3. Django中的check指令和sqlmigrate指令

    官方文档的解释如下: Django 有一个自动执行数据库迁移并同步管理你的数据库结构的命令 - 这个命令是 migrate,我们马上就会接触它 - 但是首先,让我们看看迁移命令会执行哪些 SQL 语句 ...

  4. 「题解」「CF468D」树中的配对

    目录 题目大意 思路 源代码 本博客除代码之外,来自 skylee 大佬. 题目大意 一棵\(n(n\le10^5)\)个编号为\(1\sim n\)的点的带边权的树,求一个排列\(p_{1\sim ...

  5. 使用prepareStatement执行的sql语句的写法:

    使用prepareStatement对象执行的增.删.改.查sql语句: 查:  String sql = "SELECT * FROM 表名 WHERE loginId=? AND pas ...

  6. bbs系统的相关知识点

    1.注册功能 1.注册功能往往都会由很多校验性的需求 所以这里我们用到了forms组件 项目中可能有多个地方需要用到不同的forms组件 为了解耦合 但是创建一个py文件 专门用来存放项目用到的所有的 ...

  7. python 鸢尾花数据集报表展示

    import seaborn as snsimport pandas as pdimport matplotlib.pyplot as pltsns.set_style('white',{'font. ...

  8. js实现图片选中马上显示功能,选择后可以预览,即选即显

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. python浅析模块,包及其相关用法

    一,模块 什么是模块? 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里面,代码会越来越长,越来越不容易维护. 为了编写可以维护的代码,我们把很多函数分组,分别放到不同额文件,这样,每个文 ...

  10. 题解 CF546B Soldier and Badges

    CF546B Soldier and Badges 简单的贪心qwq 排个序,如果当前数与之前的数相重,已经用过,则加到一个之前没有用过的数 #include<cstdio> #inclu ...