-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1380A - Three Indices.cpp
76 lines (56 loc) · 1.43 KB
/
1380A - Three Indices.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
You are given a permutation p1,p2,…,pn. Recall that sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.
Find three indices i, j and k such that:
1=i<j<k=n;
pi<pj and pj>pk.
Or say that there are no such indices.
Input
The first line contains a single integer T (1=T=200) — the number of test cases.
Next 2T lines contain test cases — two lines per test case. The first line of each test case contains the single integer n (3=n=1000) — the length of the permutation p.
The second line contains n integers p1,p2,…,pn (1=pi=n; pi?pj if i?j) — the permutation p.
Output
For each test case:
if there are such indices i, j and k, 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
inputCopy
3
4
2 1 4 3
6
4 6 1 2 5 3
5
5 3 1 2 4
outputCopy
YES
2 3 4
YES
3 5 6
NO
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector <int> v(n);
for (auto &x: v) cin >> x;
bool res = false;
for (int i = 1; i < n - 1; i++) {
if (v[i - 1] < v[i] && v[i] > v[i + 1]) {
cout << "YES\n";
cout << i << " " << i + 1 << " " << i + 2 << "\n";
res = true;
break;
}
}
if (!res) cout << "NO\n";
}
return 0;
}