/* Bismillah * Author: Akhyar Ahmed Turk * Created: 2025-12-29 13:11 (GMT+5) * brain["Motivation"].insert("Ya to win hy ya learn"); * Those who can't remember the past are condemned to repeat it. * -Dynamic Programming. */ #include #include #include using namespace std; using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; // use when u need indexing in sets like (when you need lower upper bound while frequently updating set) // idx.order_of_key(value) for nums #define pb push_back #define f first #define ss second #define vi vector #define vb vector #define vvi vector #define all(a) a.begin(), a.end() #define allr(a) a.rbegin(), a.rend() #define mod 1000000007 #define mod2 998244353 const int inf = 1e17 + 1; #define INT_MAX LLONG_MAX #define nl "\n" #define forn(i, a, b) for (int i = a; i < b; i++) #define forr(i, a, b) for (int i = a; i >= b; i--) #define input(vec, n) for(int z = 0; z < (n); z++) cin >> vec[z]; struct comp{ bool operator()(pii &a,pii &b){ if(a.f==b.f) return a.ss>b.ss; return a.f>n; string s; cin>>s; vi arr(n); input(arr,n); vi res1={0},res2={0}; vector mp; forn(i,0,n){ int a=0,b=0; forn(j,i,n){ a+=arr[j]; b+=(s[j]=='E'); mp.pb({a,b}); } } sort(all(mp),comp()); for(auto it:mp){ if(it.ss<=res2.back()) continue; res1.pb(it.f); res2.pb(max(it.ss,res2.back())); } int k ;cin>>k; while(k--){ int a; cin>>a; int d=upper_bound(all(res1),a)-res1.begin()-1; cout<> t; while (t--) { solve(); } return 0; }