Help needed for giving output on multiple test cases

Usually i create a to_print() vector and iterate through it after running my main program for multiple test cases, but I think it increases my runtime and might be the cause for my TLE. But why i try cout for after each test case, i get wrong answer. Please help me solve this. Thanks

Just use this simple template, and then the problem wouldn’t happen if your code is correct. As is obvious, you need to input and solve each test case inside the while loop.

using namespace std;
int main(){
    int t;
        int ans=0;
1 Like