2016 省赛热身 Handshakes

Handshakes

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 a1a2, ..., 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<stdio.h>
#include<string.h>
using namespace std;
#define maxn 100010
int a[maxn];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        int n;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        int ans=0,sum=0;
        for(int i=n-1;i>=0;i--)
        {
            if(a[i])       sum++;
            a[i] += (sum-1);
            ans = max(ans,a[i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}
				
时间: 2024-10-26 09:45:16

2016 省赛热身 Handshakes的相关文章

2016 省赛热身 2016

2016 Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (u

2016 省赛热身 2016 Programming Ability Test

Programming Ability Test Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description Programming Ability Test (PAT) aims to evaluate objectively, through unified examinations with automatic online judging system, the abilit

2016 省赛热身 Ellipse

Ellipse Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description There is an beautiful ellipse whose curve equation is: . There is a parallelogram named P inscribed in this ellipse. At the same time, the parallelogram P 

2016 省赛热身 In the Rain

In the Rain Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description Fujiwara no Mokou was formerly an ordinary human, but she became an immortal being after drinking the Hourai Elixir about 1300 years ago. She has some

2016湖南省赛----A 2016 (同余定理)

2016湖南省赛----A 2016 (同余定理) Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤10 9). Output 对于每组数据,输出一个整数表示满足条件的数量. Sample Input 32 63 2016 2016 1000000000 1000000000 Sample

(三角剖分)三角形和矩形的面积交 2016湖南省赛

1 // (三角剖分)三角形和矩形的面积交 2016湖南省赛 2 3 #include <iostream> 4 #include <cstdio> 5 #include <cstring> 6 #include <stack> 7 #include <queue> 8 #include <cmath> 9 #include <algorithm> 10 using namespace std; 11 12 const i

2016湖南省赛 I Tree Intersection(线段树合并,树链剖分)

2016湖南省赛 I Tree Intersection(线段树合并,树链剖分) 传送门:https://ac.nowcoder.com/acm/contest/1112/I 题意: 给你一个n个结点的树,树上每个节点有自己的颜色 问你删除第i条边后形成的两颗子树有多少个相同的颜色 题解: 树链剖分写法: 对于每一种颜色来说,如果这个颜色是在单独的一颗子树中,那么就不会对其他的边产生贡献,所以我们单独对每一种颜色对边的贡献讨论,如果这个颜色只有一个,那么就不会产生贡献,否则,他就可以在两个相同颜

2016国赛小结

与信息安全比赛结缘始于2013年. 2013年山东省没有举行省赛选拔,我们直接报名参加了国赛,仓促应战,只得了24名,三等奖. 2014年未举办国赛,下半年参加了省赛选拔,第4名,二等奖.前5名可以参加新一轮集训和选拔,我们因故弃权. 2015年访学一年,未参加比赛. 2016年上半年,没想到竟意外地被选为了国赛裁判. 通过这次裁判经历得以一窥比赛全貌,收获颇丰.总体而言,在比赛过程中应注意以下几点: 一进场时最易慌乱,这时一定要稳住.比赛中一定要仔细听裁判说什么,有不懂的一定要及时问,不可自己

2016湖南省赛 [Cloned]

A.2016 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤10 9). Output对于每组数据,输出一个整数表示满足条件的数量.Sample Input 32 63 2016 2016 1000000000 1000000000 Sample Output 1 30576 7523146895502644 代