2016河南省第九届ACM程序设计竞赛[正式赛四]

2016河南省第九届ACM程序设计竞赛[正式赛四]
-0:12:10
Current Time: 2016-04-13 13:47:49Contest Type: Private
Start Time: 2016-04-13 09:00:00Contest Status: Running
End Time: 2016-04-13 14:00:00Manager: zhongshijun
E - E
Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

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<stdio.h>
int a[109000];
int main()
{
    int t,i,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int p=0;
        for(i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==0)
            {
                p++;
            }
        }
        if(p==n)
        {
            printf("0\n");
        }
        else
        {
            int sum=0;
            i=2;
            while(i<=n)
            {
                if(a[i]!=0)
                {
                    sum=a[i];
                    for(int j=i+1; j<=n; j++)
                    {
                        if(a[j]!=0)
                        {
                            if(sum<a[j])
                            {
                                sum=a[j];
                            }
                            else
                            {
                                sum++;
                            }

                        }

                    }
                    printf("%d\n",sum);
                        break;

                }
                    else
                    {
                        i++;
                    }
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值