gettting wrong answer help

problem is:
my solution but it gives wrong answer :
using namespace std;
int main()
{ int t;
int a,b,c1,c2;
{ cin>>a>>b;
int i=0,sum=0,x;

}	if(sum<=b) 


I guess we really don’t need vectors for this problem.

I have attached the link to my solution [“click here”][1]

I have also listed the major changes you can make:

1)Remove Variables C1,C2.

2)Change variable sum from “int” to “long long”

4)And can remove vector.

Hope this is helpful to You,Happy coding:)

1 Like

hi i try this one it works:but my question is that whether c1 c2 make some error or vector is making error and sum works for int as well
using namespace std;

int main() {
int t, a, b, sum, i;
while(t–) {
while(a–) { cin>>i; sum=sum+i; }
if(sum<=b) cout<<“Yes”<<endl;
else cout<<“No”<<endl;
return 0;

@deepak_2100 Is the above code working.

Nope they are not

But we can reduce the memory used by our program

The issue with the main code was that we were adding or pushing the element at the back of Vector and trying to accessing it’s front.It will work if we change it to “push_front”.

You forgot to increment i. Add i++; after sum+=v[i];

int is sufficient for this problem. But using long long is good habit.

BeWare! with push_front on vectors. They take time proportional to size of vector. So If you are assuming time complexity to be O(n). But in fact they become O(n^2).

Instead use some other data structure for this purpose.

Other way round. Use push_back and run loop for i=n-1 to 0; :slight_smile:

Perfect Soln.

It can be actually doesn’t need any Data Structure except INT/LONG LONG

1 Like