Can some one help me with CHFICRM?

I’ve checked for the solution at a few places and in the end the logic used my me seems correct, still i keep getting WA. Please, tell me what i’m doing wrong here.

#include <bits/stdc++.h>
#define pb push_back
#define endl '\n'
#define llint long long int
#define vint vector<int>
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    llint t, n, input, fiv, ten, fif;
    bool flag;
    cin >> t;
    while(t--)
    {
        fiv = ten = fif = 0;
        flag = true;
        cin >> n; 
        while(n--)
        {
        	cin >> input;
        	if(input == 5)
        	{
        		fiv++;
			}
        	if(input == 10)
        	{
        		ten++;
				if(fiv > 0)
        		{
        			fiv--;
				}
				else
				{
					cout << "NO";
					flag = false;
					break;					
				}
			}
		}
			if(input == 15)
				{
					fif++;
					if(ten > 0)
						ten--;
					else
					if(fiv > 1)
					{
						fiv = fiv - 2;
					}
					else
					{
						cout << "NO";
    					flag = false;
    					break;
					}
				}
    	if(flag == true)
		{
			cout << "YES";	
		}	
		cout << endl;
	}
    return 0;
}

Your if statement for 15 seems to be outside while (n--). That must be the error here.

BTW, why did you steal my profile picture? :smile:

1 Like

Your if statement is outside n–
Floor Gang AAOUH!

1 Like

its a bit different but…damn

also, yes. if Statement is outside while loop…

1
3
5 15 10
expected output NO
your code output YES

Submit and check it will give AC correct answer

NO. You stole my profile picture!


Jokes aside, is your problem fixed?

1 Like

yup @ninja1918 it seems like u have bored checking the code , that’s why your if is lying outside while

Your modified correct code.
https://www.codechef.com/viewsolution/34440778

Yeah, it works. I wanna die now. :sob:

Thanks @nk20422 . It works

You’re reading the input one by one, so let’s say the array size is 15 and you find it’s not possible for i = 4, at which point you’re breaking out of the loop and printing “NO”. So this test case is fine. But when we consider the next test case, won’t your algorithm take the input of A[5] from previous test case as the n for the new test case?

Am I missing something here?

1 Like

lol…keep practicing bro and you’ll be able to solve them all next time

:exploding_head: :rofl:

Yeah, i messed that up too.