#K60472. Maximum Power Output
Maximum Power Output
Maximum Power Output
You are given an integer n representing the number of time slots. For each time slot i (using 0-indexing), you are provided with three integers:
- di – the demand of power in that time slot,
- si – the power output from source S,
- wi – the power output from source W.
You must determine if it is possible to meet the demand exactly for every time slot. In each time slot, you have two possible choices:
- If \(d_i = s_i\), you add \(s_i\) to your total power output.
- If \(d_i = w_i\), you add \(w_i\) to your total power output.
If at any time slot neither condition is met (i.e. \(d_i \neq s_i\) and \(d_i \neq w_i\)), then it is impossible to satisfy the power demand and you should output -1
.
Your task is to compute the total power output by processing each time slot in order. If all time slots can meet the demand exactly, output the sum of the matched supply outputs. Otherwise, output -1
.
inputFormat
The input is given via standard input (STDIN) and has the following format:
n d0 d1 ... dn-1 s0 s1 ... sn-1 w0 w1 ... wn-1
Where:
n
is the number of time slots.- The second line contains
n
integers representing the array \(d\), the city’s demand for each time slot. - The third line contains
n
integers representing the array \(s\), the power output from source S. - The fourth line contains
n
integers representing the array \(w\), the power output from source W.
outputFormat
Output a single integer to standard output (STDOUT). This integer is the total power output if the demand is met in every time slot; otherwise, output -1
.
4
8 7 4 5
5 3 5 6
4 5 3 2
-1