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(NS[0] == 'W') continue; let tmp = NS.substr(0, binary(NS,K[i],dp, j, v)).split("E").length-1; max = Math.max(max, tmp); } console.log(max); } } function binary(S,K,DP,j,v) { let l = 0; let r = S.length; let count = 64; while(count-- > 0) { let X = Math.floor((l + r) / 2); if(K >= DP[X+j]-v) { l = X; } else { r = X; } } return r; } //-- 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"));