#C7810. Minimum Water Adjustment Operations
Minimum Water Adjustment Operations
Minimum Water Adjustment Operations
You are responsible for managing a series of lakes. Each lake i has an initial water level \(L_i\) and a maximum safe water level (capacity) \(C_i\). To prevent flooding, you must adjust each lake so that its water level exactly matches its capacity.
In one operation, you can increase the water level of a lake by 1 unit. However, if for any lake the initial water level exceeds its capacity (i.e. \(L_i > C_i\)), then it is impossible to adjust the levels safely. In that case, your answer should be -1.
The minimum number of operations required is given by:
[ ans = \begin{cases} \sum_{i=1}^{n} (C_i - L_i), & \text{if } L_i \le C_i \text{ for all } i,\ -1, & \text{if there exists any } i \text{ with } L_i > C_i. \end{cases} ]
</p>Given the number of lakes, the list of water levels, and the list of capacities, determine the minimum number of operations required to adjust the water levels, or print -1 if it is impossible.
inputFormat
The input is provided via standard input (stdin) as follows:
- The first line contains a single integer \(n\), representing the number of lakes.
- The second line contains \(n\) space-separated integers, representing the initial water levels \(L_1, L_2, \dots, L_n\).
- The third line contains \(n\) space-separated integers, representing the capacities \(C_1, C_2, \dots, C_n\).
outputFormat
Output a single integer on standard output (stdout): the minimum number of operations required. If it is impossible to adjust the water levels (i.e. if any \(L_i > C_i\)), output -1.
## sample3
2 1 3
3 2 4
3