Please help I am a newbie here.and have a lot of doubts

why does the program gets executed successfully but not submitted .while submitting it shows wrong answer?? and also i have a problem with java scanner input it always gives NZEC.

When you submit a solution to a problem, it gets evaluated on a set of test cases. The test cases are designed in such a way that they cover “corner cases” .
So if your solution gets WA, it means that it fails on some test case.
Check your code, try to find cases where your code fails and change the code and submit again.
Also, whenever some code fails , I’ve seen many people blaming the test cases saying the test cases are wrong etc :slight_smile: . Almost 99% of the time, tests are correct :white_check_mark: .
Also keep a look out for Time limit exceeded - A brute force solution to a problem will time out when the problem has a strict time limit.
So design your problem solution based on the constraints given in the problem. Like if the time limit is 1 sec, O(n) , O(nlogn) etc will pass when n is up to 10^5 .
NZEC is non zero exit code. Could you link to the solution where you get NZEC with scanner in java?
Are you giving custom input in editor?
I don’t know a lot of stuff but I hope this helps a bit

3 Likes

*this code gives NZEC when custom input is not provided .when i give a custom input it is executed successfully but then it does not get submitted **
/
package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{ int max=0;
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int a=sc.nextInt();
int q=sc.nextInt();
int ar[]=new int[a];
int qi[]=new int[q];
for(int i=0;i<a;i++)
ar[i]=sc.nextInt();
for(int j=0;j<q;j++)
qi[j]=sc.nextInt();

	for(int i=0;i<q;i++)
	{
	    int n=qi[i];
	    for(int j=0;j<n;j++)
	    { 
	        if(ar[j]>max)
	        max=ar[j];
	    }
	    System.out.println(max);
	}
	
}

}

As @ssjgz always says,
Format your code please and provide a link to the question :slight_smile:
If custom input is not provided and you try to run it, NZEC may occur because no input is provided.
If you give custom input and the program runs but it gives WA then there is an issue in the logic.
What do you mean btw by “it does not get submitted” => NZEC / WA?

1 Like

hey thanks for replying
okay:) I m learning
link: CodeChef: Practical coding for everyone

yes WA on all the subtasks and also TLE.

can u help me in this …i am getting TLE as of my knowledge it should work in O(n) time
using partitioning strategy…
#include<bits/stdc++.h>
using namespace std;
int partition(int *arr,int l,int r){
int i=l-1;
for(int j=l;j<r;j++){
if(arr[j]<arr[r]){
i++;
swap(arr[i],arr[j]);
}
}
swap(arr[i+1],arr[r]);
return i+1;
}
main(){
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++) cin>>arr[i];
int k,l=0,r=n-1;
cin>>k;
while(true){
int pivot=partition(arr,l,r);
if(pivot+1==k) break;
else if(pivot+1>k) r=pivot-1;
else if(pivot+1<k) l=pivot+1;
}
cout<<arr[k-1]<<“\n”;
}
}

Hey, the problem with your code is something relating to max variable.
Think about where you’ve initialized it :wink:
And see the output for same sample array input but query order 5 3 2 .
Your program will output
9
9
9
Why? :slight_smile:

1 Like

I’ll have a look once I get back :slight_smile:

ohh yes
thanks!!

what things or constranits should we check to get all the sub tasks correct?
i m not getting a single one accepted :no_mouth: