-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.java
More file actions
47 lines (42 loc) · 1003 Bytes
/
Copy pathA.java
File metadata and controls
47 lines (42 loc) · 1003 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
39
40
41
42
43
44
45
46
47
import java.util.*;
public class ans{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int c0=sc.nextInt();
int c1=sc.nextInt();
int h=sc.nextInt();
String s=sc.next();
int count0=0,count1=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='0'){
count0++;
}
else{
count1++;
}
}
int res=count0*c0+count1*c1;
int x=count1;
int y=count0;
int temp0=count0,temp1=count1;
for(int i=1;i<=x;i++){
temp0++;
temp1--;
int r=(temp0*c0+temp1*c1)+(i*h);
res=Math.min(res,r);
}
temp0=count0;
temp1=count1;
for(int i=1;i<=y;i++){
temp0--;
temp1++;
int r=(temp0*c0+temp1*c1)+(i*h);
res=Math.min(res,r);
}
System.out.println(res);
}
}
}