time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 4output
Copy
YES 2 3 4 YES 3 5 6 NO
解题说明:水题,遍历数组查找满足条件的值即可。
#include<stdio.h> #include<stdlib.h> int main() { int t; scanf("%d", &t); while (t--) { int n, a[1000], f = 0, i; scanf("%d", &n); for (i = 0; i<n; i++) { scanf("%d", &a[i]); } for (i = 1; i<n - 1; i++) { if ((a[i] > a[i - 1]) && (a[i] > a[i + 1])) { printf("YES\n"); printf("%d %d %d\n", i, i + 1, i + 2); f = 1; break; } } if (f == 0) { printf("NO\n"); } } return 0; }
