Simple input (i am not able to store the elements if i am using array to store it then i am not able terminate my array )

Sir , I have made a code for it and even tried lot of times but i am not able to clear all testcases could you please help me to sort it out :slight_smile:

You didn’t have to store elements in array
take input untill your sum non negative

Reference Code

#include<iostream>

using namespace std;

int main()
 {
	 int n,sum=0;
	 while(1)
	 {
       cin>>n;
	   sum=sum+n;
	   if(sum>=0)
	   {
		   cout<<n<<endl;
	   }
	   else
	   break;
	 }
	return 0;
}