function main(input) { let [N] = getIntegers(input); let S = input.shift(); let A = getIntegers(input); let [Q] = getIntegers(input); let K = getIntegers(input); let dp = [A[0]]; for(let i=1; i0) { v += A[j-1]; } if(S[j] == 'W') continue; let tmp = dp2[j+binary(S,K[i],dp, j, v)] - (j>0 ? dp2[j-1] : 0); max = Math.max(max, tmp); } list.push(max); } console.log(list.join("\n")); } function binary(S,K,DP,j,v) { let l = 0; let r = S.length; while(r - l > 1) { let X = Math.floor((l + r) / 2); if(K >= DP[X+j]-v) { l = X; } else { r = X; } } return l; } //-- functions ------------------------------------ function getIntegers(lines) { return lines.shift().split(" ").map(function(e) { return Number(e); }); } function getBigIntegers(lines) { return lines.shift().split(" ").map(function(e) { return BigInt(e); }); } function getStrings(lines) { return lines.shift().split(" "); } function twoDimenArrayByValue(h, w, value) { const list = new Array(h); for(let i=0; i 0) str += " "; str += e; }); return str; }; main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));