LECANDY - Editorial

You don’t seem to have made any Submissions. Are you trying to “Run” without providing Custom Input?

Yeah that was precisely the problem!

1 Like

T=int(input())
for i in range(T):
N,C=map(int,input().split())
A=[]
A=list(map(int,input().split(’ ')))
sum=C
flag=0
for j in range(N):
sum=sum-A[j]
if(sum<0):
flag=1
break;
if(flag==0):
print(‘Yes’)
else:
print(‘No’)

#include <stdio.h>

int main(void) {
// your code goes here
int satisfactionCandies;
int noOfElephants[10],test,noOfCandies;
int i;
scanf("%d",&test);
for(i=1;i<=test;i++)
{
scanf("%d",&noOfElephants[i]);

    	scanf("%d",&noOfCandies);
}
for(i=1;i<=noOfElephants[i];i++)
{
    scanf("%d",&satisfactionCandies);
}


while(noOfCandies>=satisfactionCandies)
{
    noOfCandies--;
    printf("Yes");
}
printf("No");

return 0;

}

Can anyone help me out.What is the mistake in above code.

Why i am getting NZEC Error

class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int testcases = sc.nextInt();
while(testcases > 0){
int elephant = sc.nextInt();
int candies = sc.nextInt();
int[] candiesArr = new int[elephant];
for(int i=0; i<candiesArr.length; i++){
candiesArr[i] = sc.nextInt();
}
int totalCandies = 0;
for(int i=0; i<candiesArr.length; i++){
totalCandies += candiesArr[i];
}
String result = totalCandies > candies ? “No” : “Yes”;
System.out.println(result);
testcases–;
}
}
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

He solved it. Maybe trying to “Run” without Providing “Custom Input”?

1 Like

what is the problem with this code:

while t:
    total=0
    n,c=map(int,input().split())
    k=input().split()
    for i in range(n):
        total+=int(k[i])
    if total<=c:
        print('YES')
    else:
        print('NO')
    t=t-1```

t is not defined anywhere.

2 Likes

Please check this

# cook your dish here
t=int(input())
while t:
    total=0
    n,c=map(int,input().split())
    k=input().split()
    for i in range(n):
        total+=int(k[i])
    if total<=c:
        print('YES')
    else:
        print('NO')
    t=t-1
2 Likes

This fails for the sample test input - the output has to match exactly, remember! :slight_smile:

1 Like

No Sample input output is matching

If you say so :slight_smile: :man_shrugging:

1 Like

But it’s showing wrong answer?:face_with_monocle:

please help, VS code had implemented but codechef IDE doen’t respond

#include <stdio.h>

int main() {
	int T;
	scanf("%d",&T);
	
	for(int i=0;i<T;i++){
	    int N,C;
	    scanf("%d %d",&N,&C);
		int candyRequired[N];
	    int sum=0;
	    
	    for(int j=0;j<N;j++){
	        scanf("%d",&candyRequired[j]);
	    }
	    
	    for(int j=0;j<N;j++){
	        sum = sum + candyRequired[j];
	    }
	    
	    if(sum <= C){
	        printf("Yes");
	    }
	    else{
	        printf("No");
	    }
	}
	return 0;
}

#include
using namespace std;

int main() {
int T,N,C,i,t;
int K[100];
std::cin >> T;
for(t=0;t<T;t++){
std::cin >> N >> C;
for(i=0;i<N;i++){
std::cin >> K[i];
}
for(i=0;i<N;i++){
C-=K[i];
}
if(C>=0){
std::cout << “Yes” << std::endl;
}else{
std::cout << “No” << std::endl;
}
}
return 0;
}

Can we just declare “int t” and not initialize it in the Line 3 of your code?
I am getting a “SIGTSTP error - Time limit exceeded” if I do not initialize t=0 while its declaration in my code. It works fine if I initialize t=0 while its declaration.
As I am taking its value as input in the very next line, why do I need to initialize it during declaration?
My solution code is here.

Are you trying to “Run” without Providing “Custom Input”?

It works fine if I provide the sample test cases in custom input. If I try to run it without using custom input, then this problem occurs.

#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,c;
cin>>n>>c;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int s=0;
for(int i=0;i<n;i++)
{
s=s+a[i];
}
if(s<=c){
cout<<“Yes”<<"\n";
}
else{
cout<<“No”<<"\n";
}
}
return 0;
}

Could someone please explain, why this code is not working? TIA!

#include <iostream>
using namespace std;

int main()
{
int t, n, c, a;
bool happy = true;

cin >> t;

for (int i = 0; i < t; i++)
{
    cin >> n >> c;
    for (int j = 0; j < n; i++)
    {
        cin >> a;
        c -= a;
        if (c < 0)
        {
            happy = false;
            break;
        }
    }
    if (happy)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

return 0;
}