package main import ( "fmt" "bufio" "os" ) type Enemy struct { n int s []int a []int } func main() { r := bufio.NewReader(os.Stdin) w := bufio.NewWriter(os.Stdout) defer w.Flush() enemy := new(Enemy) fmt.Fscan(r, &enemy.n) var s string fmt.Fscan(r, &s) enemy.s = make([]int, enemy.n) enemy.a = make([]int, enemy.n) for i := 0; i < enemy.n; i++ { if s[i] == 'E' { enemy.s[i] = 1 } fmt.Fscan(r, &enemy.a[i]) } var Q int fmt.Fscan(r, &Q) for i := 0; i < Q; i++ { var k int fmt.Fscan(r, &k) fmt.Fprintln(w, enemy.max(k)) } } func (this *Enemy) max(k int) int{ maxres := 0 res := 0 s, t, sum := 0, 0, 0 for true { for t < this.n && sum <= k { sum += this.a[t] res += this.s[t] t++ } if sum <= k { if res > maxres { maxres = res } break } if res - this.s[t-1] > maxres { maxres = res - this.s[t-1] } sum -= this.a[s] res -= this.s[s] s++ } return maxres }