There was a problem called little elephant and candies and here are the link and code I wrote respectively :
Link:
My code:
#include <iostream>
using namespace std;
int main()
{
int number;
cin>>number;
int elephants,candies,total_happy;
for(int i=0;(i<number)&&(number<=1000);i++)
{
total_happy=0;
int happy[elephants];
cin>>elephants>>candies;/// First line of input
for(int i=0;i<elephants;i++) /// Second line second line of input
{
cin>>happy[i];
total_happy+=happy[i];
}
if(total_happy>candies){
cout<<"No"<<endl;
}
else{
cout<<"Yes"<<endl;
}
}
}
I honestly feel my logic is right because it works for all the test cases. I don’t understand why it says wrong when I submit it.
It sometimes even says Runtime error when i run the code but when I refresh and run it again, it gives correct output