-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy path624B2.cpp
More file actions
51 lines (49 loc) · 925 Bytes
/
624B2.cpp
File metadata and controls
51 lines (49 loc) · 925 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
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
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;
}
bool flag=true;
sort(pos,pos+m);
int i, j;
for (i = 0; i < n-1; i++){
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1]) {
if(! binary_search(pos,pos+m,j)){
flag=false;
break;
}
else
swap(&arr[j], &arr[j+1]);
}
if(!flag)
break;
}
if(flag)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}