-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBSCOST.cpp
54 lines (49 loc) · 874 Bytes
/
BSCOST.cpp
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
48
49
50
51
52
53
54
// Date - 24th September 2022
// Code by - Abhinav Anand
// Problem link -> https://www.codechef.com/problems/BSCOST
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void solve()
{
int n,x,y;
cin>>n>>x>>y;
string s;
cin>>s;
int cntz=0;
int cnto=0;
for(int i=0;i<n;i++)
{
if(s[i]=='0')
cntz++;
else if(s[i]=='1')
cnto++;
}
sort(s.begin(),s.end());
if(x>y && cntz>=1 && cnto>=1)
{
cout << y << endl;
}
else if(y>x && cntz>=1 && cnto>=1)
{
cout << x << endl;
}
else if(x==y && cntz>=1 && cnto>=1)
{
cout << y << endl;
}
else if(cntz<1 || cnto<1)
{
cout << 0 << endl;
}
}
int main() {
ll t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}