-
Notifications
You must be signed in to change notification settings - Fork 0
/
Array_fix.cpp
49 lines (48 loc) · 1.13 KB
/
Array_fix.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
#include<bits/stdc++.h>
using namespace std;
void ispossible(vector<long long int>&arr){
for(int i = arr.size()-1;i>=1;--i){
if(arr[i] < arr[i-1]) {
bool ans = arr[i-1]/10 < arr[i-1]%10 && arr[i-1]%10 < arr[i];
if(!ans){ cout<<"NO"<<endl; return ;}
}
}
cout<<"YES"<<endl;
}
void solve(vector<long long int>&arr){
long long curr =0;
for(int i = 0;i<arr.size();i++){
if(arr[i]<curr){
cout<<"NO"<<endl;
return ;
}
else{
long long x=arr[i]/10;
long long y=arr[i]%10;
if(x>=curr){
if(y>=x){
curr=y;
}
else{
curr = arr[i];
}
}
else{
curr = arr[i];
}
}
}
cout<<"YES"<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
int s;
cin>>s;
vector<long long int>arr(s);
for(int i =0;i<s;i++) cin>>arr[i];
solve(arr);
solve(arr);
}
}