Hackerearth: Fredo and Game

code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,a,n;
    cin>>t;
    while(t--)
    {
        cin>>a>>n;
        int arr[n];
        for(i=0; i<n; i++)
        {
            cin>>arr[i];
        }
        for(i=0; i<n; i++)
        {
            if(arr[i]==1)
                a=a+2; //from the question  //you gain three units ammo and lose one unit of ammo. When you don't hit an obstacle, you lose one unit ammo. If at any instance, you are left with  ammo units, the game ends there.
            else
                a=a-1;
            if(a<=0)
                break;
        }
        if(i<n-1)//how much time it has iterated
            cout<<"No"<<" "<<i+1<<"\n"; //this logic is critically need to think
        else{
            cout<<"Yes"<<" "<<a<<"\n";
        }
    }
    return 0;
}

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.