My issue
My code
#include <stdio.h>
int main(void) {
// your code goes here
int t;
scanf("%d",&t);
while(t--)
{
int n,x,y;
scanf("%d %d %d",&n,&x,&y); int count0=0, count1=0;
char a[n];
scanf("%s",a);
for(int i=0; i<n; i++)
{
if(a[i]=='0')
count0++;
else
count1++;
}
if(count1==0 || count0==0)
printf("0\n");
else
printf("%d\n",x>y?y:x);
}
return 0;
}
Problem Link: BSCOST Problem - CodeChef
What’s wrong in this code?
The logic that I’ve used is, if all the characters are either 1 or 0, then tax would be zero.
Otherwise
the minimum of the two taxes would be the answer because incase x<y we can arrange the string as 000111 type such that there’s one 1 “01” combination and incase y<x, we can arrange it as 111000 type such that there’s only one “10” combination.