82382024-01-13 19:19:30mmatedLegtöbb gyümölcs (40 pont)cpp17Accepted 40/406ms5596 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define f(i,k,n) for(int i=k; i<n; i++)

void solve()
{
    int n;
    cin>>n;
    int a[n],k[n];
    char x;
    cin>>x;
    a[0]=x=='A';
    k[0]=x=='K';
    f(i,1,n)
    {
        cin>>x;
        a[i]=a[i-1];
        k[i]=k[i-1];
        if(x=='A')  a[i]++;
        else    k[i]++;
    }
    int maxi=0;
    f(i,0,n)    if(n/2-k[i]>=a[i])    maxi=max(maxi,2*a[i]);
    cout<<maxi<<"\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--)  solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1892 KiB
2Accepted0/06ms3632 KiB
3Accepted2/23ms2292 KiB
4Accepted2/23ms2504 KiB
5Accepted2/23ms2740 KiB
6Accepted2/23ms2944 KiB
7Accepted2/23ms2872 KiB
8Accepted3/33ms3012 KiB
9Accepted3/33ms3096 KiB
10Accepted3/33ms3364 KiB
11Accepted3/34ms4244 KiB
12Accepted3/34ms4412 KiB
13Accepted3/34ms4832 KiB
14Accepted3/34ms5056 KiB
15Accepted3/36ms5596 KiB
16Accepted3/36ms5556 KiB
17Accepted3/36ms5368 KiB