Why is my Code giving WA for Second TC

My code is giving WA for second TC. Any logic error? Please help.
Problem: Codechef Starters Problem 2

#include <bits/stdc++.h>
#define ll long long
#define lb lower_bound
#define ub upper_bound
using namespace std;
void solve()
{
    string s;
    ll x,y;
    cin>>x>>y;
    cin>>s;
    ll temp=1;
    ll streak=0;
    ll salary=0;
    for(ll i=0;i<30;i++)
    {
        if(s[i]=='1')
        {
            salary+=x;
        }
    }
    for(ll i=0;i<30;)
    {
        if(s[i]=='1' && s[i+1]=='1')
        {
            while(s[i]=='1')
            {
                temp++;
                i++;
            }
            if(temp>streak)
            {
                streak=temp;
            }
            temp=1;
            continue;
        }
        i++;
    }
    salary=salary+ (streak*y);
    cout<<salary<<endl;


}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}

On my machine, it gives the wrong answer for the sample test input, too.

1 Like

Thankyou, for your time I have solved the question. Updated code:

#include <bits/stdc++.h>
#define ll long long
#define lb lower_bound
#define ub upper_bound
using namespace std;
void solve()
{
    string s;
    ll x,y;
    cin>>x>>y;
    cin>>s;
    ll temp=0;
    ll streak=0;
    ll salary=0;
    for(ll i=0;i<30;i++)
    {
        if(s[i]=='1')
        {
            salary+=x;
        }
    }
    for(ll i=0;i<30;)
    {
        temp=0;
        if(s[i]=='1')
        {
            while(s[i]=='1')
            {
                temp++;
                i++;
            }
            if(temp>streak)
            {
                streak=temp;
            }
            continue;
        }
        i++;
    }
    salary=salary+ (streak*y);
    cout<<salary<<endl;


}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int t;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        solve();
    }
    return 0;
}
2 Likes