A bulb can be βONβ or βOFFβ. Mr. Navdeep got βnβ number of bulbs and their status, whether they are βONβ or βOFFβ. Their status is represented in a string of size βnβ consisting of 0βs and 1βs, where β0β represents the bulb is in βOFFβ condition and β1β represent the bulb is βONβ. Mr. Navdeep has been given the task to light up all the bulbs.
He can perform two operations.
First, chose any segment of bulbs and reverse them means chose any substring and reverse it. E.g. β0 110 001β -> β0 011 001β. Substring (1, 3) is reversed here. This operation will cost him Rs. βXβ.
Second, chose any segment of bulbs and reverse their present condition. i.e. if the bulb is βONβ, make it βOFFβ and if it is βOFFβ, make it βONβ. E.g. β0 011 001β -> β0 100 001β. Substring (1, 3) is complemented. This operation will cost him Rs. βYβ.
You need to help Mr. Navdeep that how much minimum amount it will require to make all the bulbs lightened. (or make all the characters as β1β in the representation string)
Input Format:
The first line will contain three space separated integers: βnβ, βXβ, βYβ denoting the number of bulbs, cost of first operation and cost of second operation respectively.
The second line contains a representation string of length βnβ consisting of 0βs and 1βs representing whether the bulb is βOFFβ or βONβ.
Output Format:
Print a single integer denoting the minimum cost required to light up all the bulbs.
Constraints:
1 <= n <= 3,00,000
0 <= X, Y <= 10^9
Time Limit: 1 second
publicclassMain {publicstaticlongminCost(int n,int x,int y,String str) {// Finding number of groups of continous zeroslong groups =0;for (int i =0; i < n; i++) {if (str.charAt(i) =='0') {int t = i;while (t < n &&str.charAt(t) =='0') t++; groups++; i = t -1; } }// If all 1sif (groups ==0)return0;// Now we have "groups", now we need to bring these groups together into 1// single group, this can by done by flipping or rotating in some order// In the end we will add the final flip cost(y) to flip the group of 0s -> 1sreturn (groups -1) * (long) Math.min(x, y) + (long) y; }}