Last week, n students participated in the annual programming contest of Marjar University. Students are labeled from 1 to n. They came to the competition area one by one, one after another in the increasing order of their label. Each of them went in, and before sitting down at his desk, was greeted by his/her friends who were present in the room by shaking hands.

For each student, you are given the number of students who he/she shook hands with when he/she came in the area. For each student, you need to find the maximum number of friends he/she could possibly have. For the sake of simplicity, you just need to print the maximum value of the n numbers described in the previous line.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1 ≤ n ≤ 100000) – the number of students. The next line contains n integers a1, a2, …, an (0 ≤ ai < i), where ai is the number of students who the i-th student shook hands with when he/she came in the area.

Output

For each test case, output an integer denoting the answer.

Sample Input

2

3

0 1 1

5

0 0 1 1 1

Sample Output

2

3

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h> using namespace std;
#define MAX 100000
long long int a[MAX+5];
long long int s[MAX+5];
long long int b[MAX+5];
int t;
int n;
long long int sum;
int main()
{
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
scanf("%d",&n);
sum=0;s[0]=0;
//memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{ scanf("%lld",&a[i]);
if(a[i]>=1)
b[i]=1;
else
b[i]=0;
s[i]=s[i-1]+b[i]; }
for(int i=1;i<=n;i++)
{
sum=max(sum,s[n]-s[i]+a[i]);
}
printf("%lld\n",sum);
}
}
return 0;
}

ZOJ 3932 Handshakes的更多相关文章

  1. ZOJ - 3932 Handshakes 【水】

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3932 题意 给出 N 个人,然后 1-N 然后 从 1 - N ...

  2. ZOJ 3923 Handshakes

    水题. 算一下每个人和之前的人握手次数+之后的人和这个人握手次数.取最大值. #include<cstdio> #include<cstring> #include<cm ...

  3. ZOJ 3932 Deque and Balls

    There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. ...

  4. Handshakes(思维) 2016(暴力)

    Handshakes Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Sta ...

  5. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  8. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  9. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

随机推荐

  1. ilmerge工具合并多个DLL或EXE

    这是一个微软提供的合并多个DLL 或是将DLL合并进EXE的工具 首先下载这个工具:ilmerge http://www.microsoft.com/en-us/download/details.as ...

  2. 整合quickx到普通cocos2dx

    quickx是对cocos2dx的lua扩展,它做了一些C++的扩展,同时还在lua做了一些封装, 让用lua开发cocos2dx更快,中文站http://quick.cocoachina.com/. ...

  3. hdu1285 确定比赛名次(拓扑排序多种方法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1285 Problem Description 有N个比赛队(1<=N<=500),编号依次 ...

  4. SenCha Touch 与 EXTJS 安装Myeclipse 插件

    http://www.cnblogs.com/jirimutu01/default.html 关于SenchaEclipsePlugin插件的安装和使用 使用过eclipse开发java程序的人都知道 ...

  5. 记一次安装多版本php的四个雷区,你踩着了吗

    记一次安装多版本php的四个雷区,你踩着了吗   技术小疯子关注3人评论740人阅读2018-06-29 15:00:30   记一次安装多版本的php的四个雷区,你踩着了吗 需求:公司需要在同一台服 ...

  6. WINDOWS中设置计划任务执行PHP文件

    1.写一个PHP程序,命名为test.php,内容如下所示: <? $fp = fopen("test.txt", "a+"); fwrite($fp, ...

  7. 如何修改织梦官方flash幻灯片的方法

    源代码: <!-- size: 280px * 192px --> <script language='javascript'> linkarr = new Array(); ...

  8. 股票指数kdj,sar,macd

    http://blog.eastmoney.com/gulingqianketong2011/blog_120832611.html http://blog.sina.com.cn/s/blog_a3 ...

  9. csdn 模式识别

    http://blog.csdn.net/liyuefeilong/article/details/45217335 模式识别 http://ceit.ucas.ac.cn/index.php?id= ...

  10. android DialogFragment 回调到 Fragment

    google 从3.0開始就引入了 Fragment 概念,用 Fragment 取代多 Activity,假设你还停留在 Activity 时代,那你就面壁去吧! Fragment 是好用,可是又几 ...