Sum or subtract numbers from an input list

Given a list of n integers v₀, …, v_(n − 1), and a string s of length n
and with characters ’+’ and ’-’, we need to print the result of summing
or subtracting each v_(i) depending on whether the i’th character of s
is ’+’ or ’-’.

Input

The input begins with a positive natural number n on a first line. On a
second line there are n integers v₀, …, v_(n). Afterwards, there’s a
sequence of lines, each with a string s of length n and characters ’+’
or ’-’.

Output

For each string s, the program has to print
(∑_(i ∈ {0…n − 1} ∧ s[i]=^(′)+^(′))v_(i)) − (∑_(i ∈ {0…n − 1} ∧ s[i]=^(′)−^(′))v_(i))

Problem information

Author: PRO1

Generation: 2026-01-25T15:18:25.246Z

© Jutge.org, 2006–2026.
https://jutge.org
