CF624div3-B. WeirdSort
WeirdSort
题目
AC代码
#include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <cstring> #include <cmath> using namespace std; typedef unsigned long long ll; ll T,N,M; ll arr[111],pos[111]; bool fun(){ sort(pos+1,pos+M+1); int tag = 1; while(tag){ tag = 0; for(int i = 1;i<=M;i++){ int j = pos[i]; if(arr[j]>arr[j+1]) { swap(arr[j],arr[j+1]); tag = 1; } } } for(int i = 1;i<N;i++){ if(arr[i]>arr[i+1]) return false; } return true; } int main(){ cin>>T; while(T--){ scanf("%lld%lld",&N,&M); for(int i = 1;i<=N;i++) scanf("%lld",&arr[i]); for(int i = 1;i<=M;i++) scanf("%lld",&pos[i]); if(fun()) puts("YES"); else puts("NO"); } return 0; }