/* ___ _ _ ___ __ ___ _ _ __ ____ ___ _ _ _ |__ /_\ |\ | | | | |__ |__| |_| |__ | |__| /_\ ___| / \ | \| | |__| ___| | | |__| |___ | | | / \ */ #include #include #include struct color { char x; int y; }; int f(struct color *, int, int); int main() { int n; scanf("%d", &n); struct color a[n]; char s[n]; scanf("%s", s); int i; for (i = 0; i < n; i++) { int v; scanf("%d", &v); a[i].x = s[i]; a[i].y = v; } int j, max = INT_MIN; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { int ans = f(a, i, j); if (max < ans) { max = ans; } } } printf("%d", max); return 0; } int f(struct color *a, int l, int h) { int i, r = 0, b = 0; for (i = l; i <= h; i++) { if (a[i].x == 'R') { r += a[i].y; } else { b += a[i].y; } } return abs(r - b); }