You are given a permutation p1,p2,…,pnp1,p2,…,pn . Recall that sequence of nn integers is called a permutation if it contains all integers from 11 to nn exactly once.
Find three indices ii , jj and kk such that:
- 1≤i<j<k≤n1≤i<j<k≤n ;
- pi<pjpi<pj and pj>pkpj>pk .
Or say that there are no such indices.
Input
The first line contains a single integer TT (1≤T≤2001≤T≤200 ) — the number of test cases.
Next 2T2T lines contain test cases — two lines per test case. The first line of each test case contains the single integer nn (3≤n≤10003≤n≤1000 ) — the length of the permutation pp .
The second line contains nn integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n ; pi≠pjpi≠pj if i≠ji≠j ) — the permutation pp .
Output
For each test case:
- if there are such indices ii , jj and kk , print YES (case insensitive) and the indices themselves;
- if there are no such indices, print NO (case insensitive).
If there are multiple valid triples of indices, print any of them.
Example
Input
Copy
3
4
2 1 4 3
6
4 6 1 2 5 3
5
5 3 1 2 4
Output
Copy
YES
2 3 4
YES
3 5 6
NO
就…硬暴力。(不过显然可以优化到O(n)QAQ
#include <bits/stdc++.h> using namespace std; int n, a[1005]; int main() { int t; cin >> t; while(t--){ cin >> n; int x = 0, y = 0, z = 0; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 2; i <= n - 1; i++){ for(int j = 1; j < i; j++){ if(a[j] < a[i]){ x = j; break; } } for(int j = i + 1; j <= n; j++){ if(a[j] < a[i]){ y = j; break; } } if(x && y){ z = i; break; }else{ x = y = z = 0; } } if(z){ cout << "YES" << endl; cout << x << ' ' << z << ' ' << y << endl; }else{ cout << "NO" <<endl; } } //system("pause"); return 0; }