Guest User

Untitled

a guest
Mar 1st, 2016
313
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. import itertools
  3.  
  4. f = sys.stdin
  5. g = itertools.accumulate
  6.  
  7. n = int(f.readline())
  8. p = list(map(int, f.readline().split()))
  9. c = f.readline()
  10.  
  11. v = [-x if y == 'B' else x for x,y in zip(p,c)]
  12. s = sum(p[i] if c[i] == 'B' else 0 for i in range(n))
  13. print(s+max(0, max(g(v)), max(g(v[::-1]))))
RAW Paste Data