Who Is In Front of Me(hrbeu1216)

Who Is In Front of Me

TimeLimit: 1 Second   MemoryLimit: 32 Megabyte

Totalsubmit: 693   Accepted: 192  

Description

There are N(1<=N<=50000)students stand in a queue.We assume that every can only see the students that are in front of him and taller than him

.

For example, there are 6 students standing in a queue with height of
4 3 1 2 5 2,begining from the front student. In this example, student 3's height is 1, and he can see 2 persons. Student 6, although many students in front are taller than him, but he can only see the student with height of 5.

Now, given the number of students in a queue, and the height of each, can you find the student that can see most persons.

Input

Input contains multiple test cases. The first line is a integer T, the number of cases.The first line of each case is a integer N, the number of students.The second line of each case contains the heights of students from front to back.

Output

For each test case, print a line with a integer M, representing the maximum number of students can someone can see.

Sample Input

2
6
4 3 1 2 5 2
3
2 2 2

Sample Output

2

0


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 50010;
int m[maxn];        //member
int num[maxn];      //record how many member in front of me;
//1216 	Accepted 	C++ 	68MS 	1128K 	1095B 	

int work(int n) {
    int index = 0;
    int max_num = 0;
    num[0] = 0;
    for(int i = 1; i < n; i++) {
        if(m[i] < m[i-1]) {
            num[i] = num[i-1] + 1;
        }
        else if(m[i] < m[index]) {
            for(int j = i-1; j >= index; j--) {
                if(m[j]>m[i]) {
                    num[i] = num[j] + 1;
                    break;
                }
            }
        }
        else{                   ///the max member
            num[i] = 0;
            index = i;
        }
        max_num = max(num[i], max_num);
    }
    return max_num;
}

int main()
{
    int T, n;
    scanf("%d", &T);
    while(T--) {
        scanf("%d", &n);
        memset(m, 0, sizeof(m));
        for(int i = 0; i < n; i++) {
            scanf("%d", &m[i]);
        }
        int res = work(n);
        cout << res << endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值