-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathOptimal_Reduction.cpp
More file actions
81 lines (68 loc) · 1.32 KB
/
Optimal_Reduction.cpp
File metadata and controls
81 lines (68 loc) · 1.32 KB
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
77
78
79
80
81
#include <bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define bp(i) __builtin_popcount(i)
ll mod=1e9+7;
int main() {
int t;
cin>>t;
while(t--)
{
int n;cin>>n;
int arr[n];
set<int>s;
for(int i=0;i<n;i++)
{cin>>arr[i];
s.insert(arr[i]);
}
int m=0,mi,f=0,k=1;
for(int i=0;i<n;i++)
{
if( f==1 && arr[i]>mi)
{ k=0; break;}
else if(arr[i]>=m)
m=arr[i];
else if(arr[i]<m)
{f=1;mi=arr[i];}
}
if(k)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
// int c=0,ans1=0,ans2=0,f=0;
// for(int i=0;i<n;i++)
// {
// arr[i]=arr[i]-ans1;
// if(arr[i]<ans1)
// continue;
// else{
// //arr[i]=arr[i]-c;
// ans1+=arr[i];
// //c+=arr[i];
// }
// }
// ans2=*max_element(arr,arr+n);
// cout<<ans1<<" "<<ans2<<endl;
// if(ans1<=ans2)
// cout<<"NO"<<endl;
// else
// cout<<"YES"<<endl;
}
}