forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CODEFORCES)Make_it_good.cpp
68 lines (60 loc) · 1.47 KB
/
(CODEFORCES)Make_it_good.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
#include <iostream>
using namespace std;
#include <vector>
int main(){
int t;
cin>>t;
for(int tt=0;tt<t;tt++){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
//int maxcount=0;
int trend;
int j;
for(j=n-1;j>0;j--){
if(a[j]>a[j-1]){
trend=0;
break;
}
else if(a[j]<a[j-1]){
trend=1;
break;
}
}
if(j==0){cout<<0<<endl;}
else{
int ans;
if(trend==0){
bool broke=false;
for(int k=j-1;k>0;k--){
if(a[k]<a[k-1]){
ans=k;
broke=true;
break;
}
}
if(!broke){ans=0;}
cout<<ans<<endl;
}
else if(trend==1){
bool switched=false;
bool broke=false;
for(int k=j-1;k>0;k--){
if(!switched){
if(a[k]>a[k-1]){switched=true;}
}
else{
if(a[k]<a[k-1]){
ans=k;
broke=true;
}
if(broke){break;}
}
}
if(!switched||!broke){ans=0;}
cout<<ans<<endl;
}
}
}
}