#include #define long long long #define up(i,a,b) for (int i=a; i<=b; i++) #define down(i,a,b) for (int i=a; i>=b; i--) #define endl '\n' #define X first #define Y second #define II pair #define debug(X) cerr<< #X << "=" <57) && c != '-') ;c = gc()); if(c=='-') {neg=1;c=gc();} for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;} if(neg) x=-x; } inline void writeln(int x){ char buffor[21]; register int i=0; int neg=0; if (x<0) {neg=1; x= -x;} do{ buffor[i++]=(x%10)+'0'; x/=10; } while(x); i--; if (neg) pc('-'); while(i>=0) pc(buffor[i--]); pc('\n'); } const int N= 5e4+10; int m,n, typ[N]; struct animal { int s,d, typ; }a[N]; int f[N], cnt[N][2]; void input() { cin>>m>>n; up(i,1,n) { char t; cin>>t; if (t== 'E') a[i].typ= 0; else if (t== 'D') a[i].typ= 1; else if (t== 'C') a[i].typ= 0; else a[i].typ= 1; } up(i,1,n) cin>>a[i].s; up(i,1,n) cin>>a[i].d; } bool byd(animal a, animal b) { return a.d< b.d; } void solve() { sort(a+1, a+1+n, byd); up(i,1,n) { up(j,0,1) cnt[i][j]= cnt[i-1][j]; cnt[i][a[i].typ]++; } int x= 1; up(i,1,n) { int typ= a[i].typ; f[i]= f[i-1]; int low, high, mid; low= 1; high= i-1; while (low<= high) { mid= (low+ high)/2; if (a[mid].d<= a[i].s) low= mid+1; else high= mid-1; } //= f[low-1] int newf= f[low-1]+ cnt[i][typ]- cnt[low-1][typ]; f[i]= max(f[i], newf); while (x<= n) { if (f[i]>= x) { cout<>test; up(i,1,test) { input(); solve(); } return 0; }