Handshakes

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

题意:一共n个人,每有一个人进房间,就会和ai个朋友握手,问拥有朋友的最大个数。

从第一个不为零的ai开始,maxn=ai。用maxn标记最大值。
如果ai为零,跳过;如果ai不为零,判断ai与maxn的大小关系,如果小于maxn,maxn++,否则,更新maxn的大小。

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=100010;
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,a[maxn],mixn=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i])
                mixn++;
            if(a[i]>mixn)
               mixn=a[i];
        }
        printf("%d\n",mixn);
    }
    return 0;
}

因为读题不清楚,题目中的ai是和其他人握手的次数,而不是和第ai个人握手,wa了好多遍,好忧桑。QAQ

你可能感兴趣的:(Handshakes)