You are given four integers n, c0, c1 and h and a binary string s of length n.
A binary string is a string consisting of characters 0 and 1.
You can change any character of the string s (the string should be still binary after the change). You should pay h coins for each change.
After some changes (possibly zero) you want to buy the string. To buy the string you should buy all its characters. To buy the character 0 you should pay c0 coins, to buy the character 1 you should pay c1 coins.
Find the minimum number of coins needed to buy the string.
Input
The first line contains a single integer t (1≤t≤10) — the number of test cases. Next 2t lines contain descriptions of test cases.
The first line of the description of each test case contains four integers n, c0, c1, h (1≤n,c0,c1,h≤1000).
The second line of the description of each test case contains the binary string s of length n.
Output
For each test case print a single integer — the minimum number of coins needed to buy the string.
Example
inputCopy
6
3 1 1 1
100
5 10 100 1
01010
5 10 1 1
11111
5 1 10 1
11111
12 2 1 10
101110110101
2 100 1 10
00
outputCopy
3
52
5
10
16
22
Note
In the first test case, you can buy all characters and pay 3 coins, because both characters 0 and 1 costs 1 coin.
In the second test case, you can firstly change 2-nd and 4-th symbols of the string from 1 to 0 and pay 2 coins for that. Your string will be 00000. After that, you can buy the string and pay 5⋅10=50 coins for that. The total number of coins paid will be 2+50=52.
边界条件去比较一下大小
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#define inf 0x3f3f3f3f
#define cha 1e-6
#define ll long long
using namespace std;
const int maxn = 200+10;
char a[1200];
int main() {
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--){
int n,c0,c1,h;
int l=0,r=0;
cin>>n>>c0>>c1>>h;
for(int i=1;i<=n;i++){
cin>>a[i];
if(a[i]=='1') l++;
else r++;
}
int sum1=n*c1+r*h;
int sum2=n*c0+l*h;
int sum3=l*c1+r*c0;
cout<<min(min(sum1,sum2),sum3)<<endl;
}
return 0;
}