How to solve this...? I tried but couldnt solve

Closing the Tweets

Problem Code: TWTCLOSE

I tried this approach and it dint work… ?? Atleast when i did a dry run for the test cases it is correct…but the compiler is not printing the desired result .

#include<bits/stdc++.h>

using namespace std;

int main()

{

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int n,k;

cin>>n>>k;

int maxi = 0;

vector<int>s(n);

while(k--)

{

    string s1,s2;

    cin>>s1;

    if(s1 == "CLOSEALL")

    {

        fill(s.begin(),s.end(),0);

        maxi = 0;

    }

    if(s1 == "CLICK")

    {

        cin>>s2;

        cout<<s2<<endl;

        int temp = stoi(s2);

        cout<<temp<<endl;

        if(s[temp] == 0)

        {

            s[temp] = 1;

            maxi++;

        }

        else

        {

            s[temp] = 0;

            maxi--;

        }

    }

    cout<<maxi<<endl;

}

return 0;

}

Editorial of the question , do give it a try
My advice : post problems link rather than its code.

2 Likes

okk thanks a lot.

Can anyone point out the mistake with this
https://www.codechef.com/viewsolution/46433911

Consider the test input:

20 2                                                    
CLICK 1
CLICK 11