Little elephant and candies wrong answer...please help..

Can someone please tell me what is wrong with this code? Thanks in advance…

#include <iostream>
 
using namespace std;
 
int main()
{
   int t,n,c,a,sum;
   cin>>t;
   while(t>0)
    {
        cin>>n>>c;
        sum=0;
        for(int i=0;i<n;i++)
           {
            cin>>a;
            sum+=a;
           }
         if(sum>=c)
            cout<<"Yes\n";
         else
            cout<<"No\n";
        t--;
    };
   
   return 0;
}

problem code : LECANDY

if(sum>=c)

you probably meant the other way… :slight_smile:

@cyberax Thank you…Could you please suggest some other approach so that i can reduce the execution time? Currently,it took 2.10 secs…

if you have a look at the fastest submitted AC solution, you can see the top code is using fast I/O operations (C code not using cin/cout streams, but getchar_unlocked/puts instead). i think you can probably try that approach. good luck !

#include
#include
using namespace std;

int main()
{
int t,n,i,a[102];
long long c,sum;
scanf("%d",&t);
while(t–)
{
sum=0;
scanf("%d %lld",&n,&c);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
if(sum<=c)
printf(“YES\n”);
else
printf(“NO\n”);

}
return 0;

}