-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path624B.cpp
More file actions
46 lines (44 loc) · 750 Bytes
/
624B.cpp
File metadata and controls
46 lines (44 loc) · 750 Bytes
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t; cin>>t;
while(t--){
ll n,m; cin>>n>>m;
int arr[n];
int pos[m];
for(int i=0;i<n;i++){
cin>>arr[i];
}
ll temp;
for(int i=0;i<m;i++){
cin>>temp;
pos[i]=temp-1;
}
sort(pos,pos+m);
char s[n-1];
for(int i=0;i<n-1;i++){
s[i]='0';
}
for(int i=0;i<m;i++){
s[pos[i]]='1';
}
int max_elem=-1;
bool flag=true;
for(int i=0;i<n-1;i++){
max_elem=max(max_elem,arr[i]);
if(s[i]=='0' && max_elem>arr[i+1]){
flag=false;
break;
}
}
if(flag)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}