-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path684A.cpp
More file actions
39 lines (36 loc) · 807 Bytes
/
Copy path684A.cpp
File metadata and controls
39 lines (36 loc) · 807 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n,c0,c1,h;
scanf("%d %d %d %d", &n, &c0, &c1, &h);
char arr[n];
getchar();
int zero = 0, one = 0;
for (int i = 0; i < n; i++)
{
scanf("%c", &arr[i]);
if(arr[i]=='0')zero++;
else one++;
}
long long int ans[n+1];
for (int i = 0; i <= n; i++)
{
ans[i] = (i*c1);
ans[i] += (n-i)*c0;
if(i <= one){
ans[i] += (one-i)*h;
}
else
{
ans[i] += (i-one)*h;
}
}
sort(ans,ans+n+1);
printf("%lld\n",ans[0]);
}
}