### [Solved] There are N houses (numbered from 0 to N-1) in the Green District

There are N houses (numbered from 0 to N-1) in the Green District. Until now, all of the houses have been using energy from the power plant. The energy demand of the K-th house is A[K] units. The residents of the Green District have decided that they should switch to renewable energy sources and want the total demand for energy from the power plant in the district to become non-positive. In other words, the sum of energy demands over all houses should become less than or equal to zero. For this purpose they are going to install solar panels on the roofs of some of the houses. One of two types of solar panels can be installed on each of the houses: • The first type costs X. Installing this type on a house generates the exact amount of energy that the house demands. After the installation, the house does not need to draw energy from the power plant anymore (its energy demand becomes 0). • The second type casts Y. It generates twice as much energy as the house demands. The surplus is transferred into the network and can be used by other houses inside the district. It means that after installing this type of panel on the roof of the K-th house, instead of having an A[K] energy demand, the house produces A[K] energy (which is the equivalent of having a -A[K] energy demand).

2. Given A = [4, 2, 7]X = 4 and Y = 100, the function should return 12. We can install a solar panel of the first type on each of the houses, therefore reducing their energy demand to 0. The total cost of the installations is 4 + 4 + 4 = 12. After these three installations, the total energy demand is equal to 0 as A = [0, 0, 0). 3. Given A = [2,2,1,2,2), X = 2 and Y = 3, the function should return 8. Non-positive power plant energy demand can be achieved with three installations: a solar panel of the second type on A[1]. changing its demand from 2 to a production of 2 for a cost of 3, a solar panel of the second type on A[3], changing its demand from 2 to a production of 2 for a cost of 3 and a solar panel of the first type on A[4], reducing its demand from 2 to 0 for a cost of 2. The total cost of the installations is 3 + 3 + 2 = 8. After these three installations, the total energy demand is equal to -1 as A = 12,-2, 1, -2,0). 4. Given A = [4, 1, 5, 3), X = 5 and Y = 2, the function should return 4. Non-positive power plant energy demand can be achieved by installing two solar panels of the second type: one on A[O] and one on A[3]. The total cost of the installations is 2 + 2 = 4. After these two installations, the total energy demand is equal to -1 as A = (-4, 1 5,-3).

The cost of installation of each kind of solar panels is the same for all houses. What is the minimum cost to make the total demand for power plant energy in the district non-positive? Write a function: class Solution { public int solution(int[] A, int x, int Y); } that, given an array A of Nintegers, denoting the energy demand for each of the houses, an integer X and an integer Y, returns the minimum cast to make the total demand for power plant energy in the Green District non-positive. Examples: 1. Given A = [5, 3, 8, 3, 2], X = 2 and Y = 5, the function should return 7. Non-positive power plant demand can be achieved by installing two solar panels: A panel of the first type on house number 0, which will reduce the demand of A[0] from 5 to 0 for a cost of 2, and a panel of the second type on A[2], changing its demand of 8 to a production of 8 units for a cost of 5. The total cost of the installations is 2 + 5 = 7. After these two installations, the total energy demand is equal to 0 = 0 + 3-8 +3 + 2).

**Expert Answer**

OR