ENTEXAM - Editorial

Before anything- what is the significance of smallest in “(N−K)'th smallest total is x”?

can anyone tell me for which test cases this code is failing?
#include
#include
using namespace std;
int main(){
long int m,n,t,i,j,k,e,last,p,min;
cin>>t;
while(t–){

cin>>n>>k>>e>>m;
last=0;
long int ar[n-1][e],sum_ar[n],sum;
for(i=0;i<n-1;i++){
	sum=0;
	for(j=0;j<e;j++){
	cin>>ar[i][j];sum+=ar[i][j];
}sum_ar[i]=sum;
}
for(i=0;i<e-1;i++){
	cin>>p;last+=p;
}
sort(sum_ar,sum_ar+n-1);
min=sum_ar[n-k-1]-last+1;
if(min<0)cout<<0<<endl;
else if(min>m)cout<<"Impossible"<<endl;
else cout<<min<<endl;


//for(i=0;i<n-1;i++)cout<<sum_ar[i]<<" ";

}
return 0;
}

I am getting runtime error(NZEC) , don’t know why? , what is wrong with my code?

import sys
import math
import string

t=int(input())
while t>0:
n,k,e,m=list(map(int,input().strip().split(" “)))
i=1
tm=[]
while i<=n-1:
l=list(map(int,input().strip().split(” “)))
tm.append(sum(l))
i=i+1
l=list(map(int,input().strip().split(” ")))
tm.sort(reverse=True)

if sum(l)>tm[k-1]:
    print("0")
else:
    if tm[k-1]-sum(l)+1>m:
        print("Impossible")
    else:
        print(tm[k-1]-sum(l)+1)
t=t-1

import java.util.ArrayList;

import java.util.Scanner;

public class code {

public static void main(String args[])
{
	Scanner scan = new Scanner(System.in);
	Integer testCase = scan.nextInt();
	ArrayList<Integer> result = new ArrayList<>();
	if(testCase>=1 && testCase<=5)
	{
		for (int i = 0; i < testCase; i++) 
		{
			scan.nextLine();
			String str = scan.nextLine();
			String[] string = str.split(" ");
			Integer N = Integer.parseInt(string[0]);
			Integer K = Integer.parseInt(string[1]);
			Integer E = Integer.parseInt(string[2]);
			Integer M = Integer.parseInt(string[3]);
			if(K>=1 && K<N)
			{
				if(N>1 && N<10000)
				{
					if(M>1 && M<1000000000)
					{
						if(E>=1 && E<=4)
						{
							ArrayList<Integer> studentMarks = new ArrayList<>();
							for (int j = 0; j < N; j++) 
							{
								Integer sum=0;
								String str1 = scan.nextLine();
								String[] string1 = str1.split(" ");
								for (int l = 0; l < string1.length; l++) 
								{
									sum = sum+Integer.parseInt(string1[l]);
								}
								studentMarks.add(sum);
							}
							Integer his_marks = studentMarks.get(studentMarks.size()-1);
							studentMarks.remove(studentMarks.size()-1);
							for (int j = 1; j < studentMarks.size(); j++) 
							{
								Integer key = studentMarks.get(j);
								Integer k= j-1;
								while(k>=0 && studentMarks.get(k)>key)
								{
									studentMarks.set(k+1, studentMarks.get(k));
									k=k-1;
								}
								studentMarks.set(k+1,key);
							}
							Integer minimum_marks =studentMarks.get((studentMarks.size()-(N-K)));
							Integer required = (minimum_marks-his_marks)+1;
							result.add(required);
						}
					}
				}
			}
		}
	}
	for (Integer integer : result) {
		System.out.println(integer);
	}
}

}

What’s wrng with this one? Getting NZEC error!

import java.util.ArrayList;

import java.util.Scanner;

public class code {

public static void main(String args[])
{
	Scanner scan = new Scanner(System.in);
	Integer testCase = scan.nextInt();
	ArrayList<Integer> result = new ArrayList<>();
	if(testCase>=1 && testCase<=5)
	{
		for (int i = 0; i < testCase; i++) 
		{
			scan.nextLine();
			String str = scan.nextLine();
			String[] string = str.split(" ");
			Integer N = Integer.parseInt(string[0]);
			Integer K = Integer.parseInt(string[1]);
			Integer E = Integer.parseInt(string[2]);
			Integer M = Integer.parseInt(string[3]);
			if(K>=1 && K<N)
			{
				if(N>1 && N<10000)
				{
					if(M>1 && M<1000000000)
					{
						if(E>=1 && E<=4)
						{
							ArrayList<Integer> studentMarks = new ArrayList<>();
							for (int j = 0; j < N; j++) 
							{
								Integer sum=0;
								String str1 = scan.nextLine();
								String[] string1 = str1.split(" ");
								for (int l = 0; l < string1.length; l++) 
								{
									sum = sum+Integer.parseInt(string1[l]);
								}
								studentMarks.add(sum);
							}
							Integer his_marks = studentMarks.get(studentMarks.size()-1);
							studentMarks.remove(studentMarks.size()-1);
							for (int j = 1; j < studentMarks.size(); j++) 
							{
								Integer key = studentMarks.get(j);
								Integer k= j-1;
								while(k>=0 && studentMarks.get(k)>key)
								{
									studentMarks.set(k+1, studentMarks.get(k));
									k=k-1;
								}
								studentMarks.set(k+1,key);
							}
							Integer minimum_marks =studentMarks.get((studentMarks.size()-(N-K)));
							Integer required = (minimum_marks-his_marks)+1;
							result.add(required);
						}
					}
				}
			}
		}
	}
	for (Integer integer : result) {
		System.out.println(integer);
	}
}

}

What’s wrng with this one? Getting NZEC error!

https://www.codechef.com/viewsolution/15958617

Have a look at my solution and the comment on 20th line. Had to debug a lot to find that code chef compiler puts the value of 0 instead of increment by 1(number of people with that specific marks all total) in spite of using ‘++’. But I get the right answer when using ‘+1’ ironically.
Is there something wrong with in code chef compiler as ++ worked fine in visual c++ 2017

https://www.codechef.com/viewsolution/19164301
I have checked all cases where we get 0 as answer but it still shows wrong answer.Could someone find the error>

if have now corrected that mistake, still it shows not working

@tarun_174
He can.
The max marks, M is 1 to 10^9. But he can get 0.

Please upvote,I need karma to upvote or ask questions

Fixed the link. :slight_smile:

Got it finally

I appraoched the problem same as the editorial still getting wrong answer,do suggest test cases where my code is failing.
`#include<bits/stdc++.h>
using namespace std;

typedef long long int lli;
typedef long double ld;

#define FOR(a,b) for(auto i=a;i<b;i++)
#define FAIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test_cases int T;cin>>T;while(T–)

int main(){
FAIO

int N,K,E,M;
long long int temp,sum=0;
int seat;
long long int marks_of_Sergery = 0,marks_required_by_Sergery;
vector<long long int> Marks;
test_cases{
    cin>>N>>K>>E>>M;
    for(int i=0;i<N-1;i++)
    {
        for(int j=0;j<E;j++){
            cin>>temp;
            sum+=temp;
        }
        Marks.push_back(sum);sum=0;
    }
    for(int i=0;i<E-1;i++){cin>>temp;marks_of_Sergery+=temp;}
    
    sort(Marks.begin(),Marks.end(),greater<int>());
    seat=N-K-1;
    marks_required_by_Sergery=Marks[seat]+1-marks_of_Sergery;
   
    marks_required_by_Sergery=max(0LL,marks_required_by_Sergery);

    if(marks_required_by_Sergery>M){cout<<"Impossible"<<endl;continue;}
    cout<<marks_required_by_Sergery<<endl;

    //clear the variables for next input TestCase;
    Marks.clear();
    sum=0;marks_of_Sergery=0;marks_required_by_Sergery=0;
}

return 0;

}

/*

Autthor: SONUKUMARSAW
email: sonukumarsaw66@gmail.com
*/`

I tried every test case and getting every answer correctly but still it’s showing wrong answer. My solution


not able to submit reported to bug team still no change :frowning:

[quote=“kevinsogo, post:1, topic:12655”]
I have this very silly doubt ,what difference does 0LL do in the above program?
As soon as I changed 0 to 0LL,it worked completely fine.

I have tried all the test cases but still getting wrong answer
`
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
{
// your code goes here
try{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t–!=0){
int n=sc.nextInt();
int k=sc.nextInt();
int e=sc.nextInt();
long m=sc.nextInt();
int studentsMarksSum[]=new int[n-1];
int sum=0;
int sergeySumOfMarks=0;
for(int i=0;i<n-1;i++){
for(int j=0;j<e;j++){
int m1=sc.nextInt();
if(m1<=m){
sum=sum+m1;
}
}
studentsMarksSum[i]=sum;
sum=0;
}
for(int i=0;i<studentsMarksSum.length-1;i++){
int sergeyMarks=sc.nextInt();
if(sergeyMarks<=m){
sergeySumOfMarks +=sergeyMarks;
}
}
int firstLargest=Integer.MIN_VALUE;
int secondLargest=Integer.MIN_VALUE;
for(int i=0;i<studentsMarksSum.length;i++){
if(studentsMarksSum[i]>firstLargest){
secondLargest=firstLargest;
firstLargest=studentsMarksSum[i];
}
else if(studentsMarksSum[i]>secondLargest){
secondLargest=studentsMarksSum[i];
}
}
if((secondLargest-sergeySumOfMarks+1 <=m) && !(secondLargest-sergeySumOfMarks+1<0) && !(sergeySumOfMarks>secondLargest)){
System.out.println(secondLargest-sergeySumOfMarks+1);
}
else if(sergeySumOfMarks>secondLargest){
System.out.println(0);
}
else{
System.out.println(“Impossible”);
}
}
}
catch(Exception e){
}
}
}
`

I am not getting what is the error in my code as my logic is almost the same as the editorialist

this is my code

Blockquote
#include<bits/stdc++.h>
using namespace std;

void fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main()
{
fastio();
int t;//number of testcase
cin>>t;
while(t–)
{
int n,k,e,m;
cin>>n>>k>>e>>m;

  int arr[n-1][e];
  
  for(int i=0;i<n-1;i++)
  {
      for(int j=0;j<e;j++)
      {
        cin>>arr[i][j];   
      }
  }
  
  int sum=0;
  int a;
  for(int i=0;i<e-1;i++)
  {
      cin>>a;
      sum=sum+a;
  }
  
     int finalarr[n-1];
   
   int sum2=0;
   for(int i=0;i<n-1;i++)
   {
       sum2=0;
       for(int j=0;j<e;j++)
       {
           sum2=sum2+arr[i][j];
       }
       finalarr[i]=sum2;
       
   }
   
   
   
   sort(finalarr,finalarr+n-1,greater<int>());
     
    if(finalarr[k-1]-sum+1<=m&&finalarr[k-1]-sum+1>=0)
     cout<<finalarr[k-1]-sum+1<<endl;
     else
    if(finalarr[k-1]-sum+1<0)
     cout<<"0"<<endl;
    else
    cout<<"Impossible"<<endl;
}

}

@cubefreak777 @rohit272000 @rishup_nitdgp @shivam_og @rashmitha_p26 @vijju123

Brother can you please help me. I don’t know that why my code is not getting accepted. It is showing as Wrong Answer, even the output is right.

#include
#include
using namespace std;

long long totals[10011];
int main(){
int T;
cin>>T;
for(int i = 0; i < T; i++){
int T_std, K, N_Exams, M_marks;
cin>>T_std>>K>>N_Exams>>M_marks;
for(int j = 0; j<T_std - 1; j++){
long long total = 0;
for(int l = 0; l<N_Exams; l++){
int score;
cin>>score;
total += score;
}
totals[j] = total;
}
long long tk = 0;
for(int l = 0; l<N_Exams - 1; l++){
long long score;
cin>>score;
tk += score;
}
//sort(totals.begin(), totals.end(), greater());
sort(totals,totals+T_std-1);
reverse(totals,totals+T_std-1);
if(totals[K-1] > tk){
int answer = totals[K-1] - tk + 1;
if(answer > M_marks){
cout<<“Impossible”<<endl;
}
else{
cout<<answer<<endl;
}
}
else{
cout<<0;
}

    }
return 0;

}

Brother can you please help me. I don’t know that why my code is not getting accepted. It is showing as Wrong Answer, even the output is right.

#–=— code starts
from functools import reduce# cook your dish here
t =int(input())
sol=[]
for tc in range(t):
(n,k,e,m)=map(int,input().split(’ '))
no_stude = n
maximal_enrolled = k
no_of_exams = e
max_score = m
t_scores = []

for i in range(no_stude - 1):
    a = list(map(int,input().split(' ')))
    total_scor = reduce(lambda x,y:x+y,a)
    t_scores.append(total_scor)
    t_scores.sort()
# print(t_scores,'t_scores')    
S_marks = list(map(int,input().split(' ')))
S_total_marks = reduce(lambda x,y:x+y,S_marks)
# print(S_total_marks,'S_total_marks')
# print((a[len(t_scores)-k]),'second last ')
marks_needed = (t_scores[len(t_scores)-k]+1)-S_total_marks

if marks_needed >max_score:
    sol.append('Impossible')
else:
    sol.append(marks_needed)

for r in sol:
print®

any helpers in chat ???
cant find the test case this code will fail

total_marks = []
sum1 = 0
times = input()

for i in times:

n, k, e, m = map(int, input().split(' '))
for x in range(n):
    marks_ = input()
    marks_ = marks_.split()

    if x != (n - 1):
        for y in range(e):
            sum1 = sum1 + int(marks_[y])

        total_marks.append(sum1)
        sum1 = 0
        marks_.clear()
    else:
        for y in range(e-1):
            sum1 = sum1 + int(marks_[y])

        candidate = sum1
        sum1 = 0
        marks_.clear()

total_marks.sort()
if total_marks[k-1] < candidate:
    print('0')
elif (total_marks[k-1] - candidate + 1) <= m:
    print(total_marks[k-1] - candidate + 1)
elif (total_marks[k - 1] - candidate + 1) > m:
    print("Impossible")