A. Three Indices
A. Three Indices
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputYou are given a permutation . Recall that sequence of integers is called a permutation if it contains all integers from to exactly once.
Find three indices , and such that:
- ;
- and .
Input
The first line contains a single integer () — the number of test cases.
Next lines contain test cases — two lines per test case. The first line of each test case contains the single integer () — the length of the permutation .
The second line contains integers (; if ) — the permutation .
Output
For each test case:
- if there are such indices , and , 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def result(arr): | |
for i in range(1,len(arr)-1): | |
if arr[i]>arr[i-1] and arr[i]>arr[i+1]: | |
print("YES") | |
print(i,i+1,i+2) | |
return | |
print("NO") | |
t=int(input()) | |
for i in range(t): | |
n=int(input()) | |
arr=list(map(int,input().split())) | |
result(arr) |
Comments
Post a Comment
Please give us your valuable feedback