forked from deepanshumishra/JavaAndCPP_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSCOST.java
More file actions
38 lines (33 loc) · 755 Bytes
/
Copy pathBSCOST.java
File metadata and controls
38 lines (33 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package codechef_lib;
import java.util.Arrays;
import java.util.Scanner;
public class BSCOST {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i=1;i<=t;i++) {
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
int n_p = 0;
char s_arr[]=s.toCharArray();
Arrays.sort(s_arr);
boolean taking=false;
for(int j=0;j<s_arr.length;j++) {
if(s_arr[j]=='0') {
taking = true;
}
if(s_arr[j]=='1' && taking) {
n_p++;
taking=false;
}else {
continue;
}
}
System.out.println(n_p*Math.min(x, y));
}
}
}
//Accepted