60712023-10-29 15:49:16horvathabelGyros (30)cpp17Accepted 30/303ms3500 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for (int z=0;z<t;z++){
        int n,a,b;
        cin>>n>>a>>b;
        string r;
        cin>>r;
        int c=0;
        int v=0;
        int m=0;
        for (char x: r){
            if (x=='C') c++;
            if (x=='B') m++;
            if (x=='V') v++;
        }
        int a2=a;
        int b2=b;
        int vegyesdb=min(v,min(a,b));
        int ans1=0;
        a-=vegyesdb;
        ans1+=vegyesdb;
        b-=vegyesdb; 
        if(c*2<=a){
            a-=c*2;
            ans1+=c;
        }
        else{
            ans1+=a/2;
            if (a%2==1){
                a=1;
            }
            else a=0;
        }

        if (m*2<=b){
            b-=m*2;
            ans1+=m;
        }
        else{
            ans1+=b/2;
            if (b%2==1){
                b=1;
            }
            else b=0;
        }
        int ans2=0; 
        if(c*2<=a2){
            a2-=c*2;
            ans2+=c;
        }
        else{
            ans2+=a2/2;
            if (a2%2==1){
                a2=1;
            }
            else a2=0;
        }

        if (m*2<=b2){
            b2-=m*2;
            ans2+=m;
        }
        else{
            ans2+=b2/2;
            if (b2%2==1){
                b2=1;
            }
            else b2=0;
        }
        ans2+=min(v,min(a2,b2));
        cout<<max(ans2,ans1)<<endl; 
    }
}
SubtaskSumTestVerdictTimeMemory
base30/30
1Accepted0/03ms1816 KiB
2Accepted0/03ms2080 KiB
3Accepted2/23ms2260 KiB
4Accepted2/23ms2312 KiB
5Accepted2/23ms2424 KiB
6Accepted3/33ms2520 KiB
7Accepted3/33ms2668 KiB
8Accepted3/33ms2744 KiB
9Accepted2/23ms2984 KiB
10Accepted2/23ms3192 KiB
11Accepted2/23ms3428 KiB
12Accepted3/33ms3428 KiB
13Accepted3/33ms3500 KiB
14Accepted3/33ms3488 KiB