Peak

A sequence of  integers  is called a peak, if and only if there exists exactly one integer  such that , and  for all , and  for all .

Given an integer sequence, please tell us if it's a peak or not.

Input

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

The first line contains an integer  (), indicating the length of the sequence.

The second line contains  integers  (), indicating the integer sequence.

It's guaranteed that the sum of  in all test cases won't exceed .

Output

For each test case output one line. If the given integer sequence is a peak, output "Yes" (without quotes), otherwise output "No" (without quotes).

Sample Input

7
5
1 5 7 3 2
5
1 2 1 2 1
4
1 2 3 4
4
4 3 2 1
3
1 2 1
3
2 1 2
5
1 2 3 1 2

Sample Output

Yes
No
No
No
Yes
No
No
#include "iostream"
#include "cstring"
#define maxn 100010
using namespace std;
int main() {
    int t;
    int a[maxn];
    cin >> t;
    while (t --) {
        memset(a,0,sizeof(a));
        int n;
        cin >> n;
        for (int i = 1; i <= n; i ++) {
            cin >> a[i];
        }
        int l = 1,r = n;
        while (l < n && a[l] < a[l + 1]) {
            l ++;
        }
        while (r > 1 && a[r] < a[r - 1]) {
            r --;
        }
        //cout << l << r << endl;
        if (l == r && l != 1 && r != n) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值