1315B - Homecoming - CodeForces Solution


binary search dp greedy strings *1300

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

using namespace std;

typedef pair<int, int> PII;

const int N = 1e6 + 7;


void solve()
{
    int a,b,p;
    cin>>a>>b>>p;
    string s;
    cin>>s;
    int n = s.size();
    s=" "+s;
    int cnta = 0;
    int cntb = 0;
    int j = n;
    for(int i=n-1;i>=1;i--){
        //cout<<s[i];
        if(s[i]=='B'){
            if(cntb==0){
                if(p>=b){
                    p-=b;
                }else{
                    break;
                }
            }
            cnta = 0;
            j = i;
            cntb++;
        }else{
            if(cnta==0){
                if(p>=a){
                    p-=a;
                }else{
                    break;
                }
            }
            j = i;
            cntb = 0;
            cnta++;
        }
    }
    cout<<j<<'\n';
}

signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

478A - Initial Bet
981A - Antipalindrome
365A - Good Number
1204B - Mislove Has Lost an Array
1409D - Decrease the Sum of Digits
1476E - Pattern Matching
1107A - Digits Sequence Dividing
1348A - Phoenix and Balance
1343B - Balanced Array
1186A - Vus the Cossack and a Contest
1494A - ABC String
1606A - AB Balance
1658C - Shinju and the Lost Permutation
1547C - Pair Programming
550A - Two Substrings
797B - Odd sum
1093A - Dice Rolling
1360B - Honest Coach
1399C - Boats Competition
1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate