#include<stdio.h>
main()
{
int T,N,E,K,M,i,j,c,temp=0,sm,kl,kpl,smm=0;
scanf("%d",&T);
while(T!=0)
{
scanf("%d",&N);
scanf("%d",&K);
scanf("%d",&E);
scanf("%d",&M);
int a[N][E],ca[N];
for(i=0;i<n-1;i++) {="" c=“0;” for(j=“0;j<E;j++)” {="" scanf("%d",&a[i][j]);="" c+=“a[i][j];” }="" ca[i]=“c;” }="" c=“0;” for(j=“0;j<E-1;j++)” {="" scanf("%d",&a[i][j]);="" c+=“a[i][j];” }="" ca[i]=“c;” sm=“c;” for(i=“0;i<N;i++)” {="" for(j=“0;j<N-i;j++)” {="" if(ca[j]<ca[j+1])="" {="" temp=“ca[j];” ca[j]=“ca[j+1];” ca[j+1]=“temp;” }="" }="" }="" kl=“ca[K-1];” kpl=“ca[K-2];” for(i=“M;i”>=0;i–)
{ int x=sm+i;
if((x>kl) && (x<kpl)) {="" smm=“i;” }="" }="" printf("%d\n",smm);="" t–;="" }="" }="" <="" code="">
Please tell me why my code is giving a wrong answer`import java.util.*;
class Entexam{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
int N,K,E,M;
for (int p=0;p<T;p++){
N=scanner.nextInt(); //No. of students
K=scanner.nextInt(); //These many students shall pass
E=scanner.nextInt(); //no of tests
M=scanner.nextInt(); // max marks in a test
int[] marksOfOthers = new int[N-1];
for(int j=0;j<N-1;j++){
marksOfOthers[j]=0;
for(int k=0;k<E;k++){
marksOfOthers[j]+=scanner.nextInt();
}
}
//Now marks have been taken of N-1 guys
int mySum=0;
for(int i=0;i<E-1;i++){
mySum+=scanner.nextInt();
}
//I need to sort the marks array - I am using bubble sort for now
Arrays.sort(marksOfOthers);
//Now array sorted , now I just need to get its score more than the kth person's score
int targetScore = marksOfOthers[N-K-1] - mySum + 1;
if(targetScore>M){
//impossible
System.out.println("Impossible");
}else if (targetScore<0){
//possible
System.out.println(0);
}else{
System.out.println(targetScore);
}
}
scanner.close();
}
}
`
This ruby code works fine for me elsewhere but gives NZEC while submission, any suggestions ?
t = gets.to_i
t.times do
merit_list = []
input = gets.split.map(&:to_i)
n, k, e, m = input[0], input[1], input[2], input[3]
(n-1).times do
student_marks = gets.split.map(&:to_i)
merit_list.push(student_marks.sum)
end
my_marks = gets.split.map(&:to_i)
my_sum = my_marks.sum
merit_list = merit_list.sort.reverse
marks_to_get = merit_list[k-1] - my_sum + 1
if (marks_to_get <= m)
puts marks_to_get
else
puts "Impossible"
end
end
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,k,n,e;
long int o,ma;
vector<long int> m(100011);
cin>>t;
while(t--)
{
long int total;
cin >> n>>k>>e>>ma;
for(int i=0;i<n-1;i++)
{
total=0;
for(int j=0;j<e;j++)
{
cin>>o;
total+=o;
}
m[i]=total;
}
total=0;
sort(m.begin(),m.end());
reverse(m.begin(),m.end());
for(int i=0;i<e-1;i++)
{
cin>>o;
total+=o;
}
long int x=total;
long int y=m[n-k-1];
long int mx=max(0L,y-x+1);
//cout<<mx;
if(mx>ma)
cout<<"Impossible"<<endl;
else
cout<<mx<<endl;
m.clear();
}
return 0;
}
what’s wrong with my code?
Can someone take a look at my code. I’ve been trying to refine it all day!
If you want to be updated with my changes, kindly take a look over https://gist.github.com/salman-bhai/f51412bd45aa4c61c07071e089f9954e
:
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d",&t);
while(t--) {
long long int n, k, e;
long long int m;
scanf("%lld %lld %lld %lld",&n,&k,&e,&m);
long long int arr[n][e];
long long int total[n-1]={0};
for(long long int i = 0; i < n-1; i ++) {
for(long long int j = 0; j < e; j ++) {
scanf("%lld",&arr[i][j]);
total[i] += arr[i][j];
}
}
long long int sergey=0;
for(long long int i = 0; i < e-1; i ++) {
long long int temp;
scanf("%lld",&temp);
sergey += temp;
}
sort(total, total+n-1);
if(sergey > total[n-k-1])
printf("1\n");
else if(sergey <= total[n-k-1] && (total[n-k-1]-sergey+1 <= m))
printf("%lld\n",(total[n-k-1]-sergey+1));
else
printf("Impossible\n");
}
return 0;
}
[1]: http:// https://gist.github.com/salman-bhai/f51412bd45aa4c61c07071e089f9954e
The first error I noticed in your code is for cases where his total score is already large enough, that he can take get admission despite getting 0 in final exam.
Eg-
Compilation Successful
Input (stdin)
1
4 2 3 10
1 1 1
2 2 2
3 4 5
10 10
Your Output
1
Expected Output-
0
In case where his total score exceeds everyone else’s score by such a large factor, that he need not score any mark in final exam, the output should be 0, as its possible to score 0 in exam. Your program is printing 1 for that case which is incorrect (if my interpretation of Q’s line “In total there are E entrance exams, in each of them one can score between 0 and M points, inclusively” is correct)
**Anybody help me out with my code it gives wrong answers on submission **
`#include<stdio.h>
int main()
{
long long int t,n,k,e,m,numb,i,j,z;
long long int na[10000];
scanf("%d",&t);
while(t–)
{
scanf("%lld%lld%lld%lld",&n,&k,&e,&m);
for(i=0;i<n;i++)
{ na[i]=0;
if(i==(n-1))
{ for(j=0;j<e-1;j++)
{
scanf("%lld",&z);
na[i]=na[i]+z;
}
}
else
{
for(j=0;j<e;j++)
{
scanf("%lld",&z);
na[i]=na[i]+z;
}
}
}
for(i=0;i<(n-1);i++)
{
for(j=(i+1);j<(n-1);j++)
{
if(na[i]<na[j])
{ numb=na[i];
na[i]=na[j];
na[j]=numb;
}
}
}
numb=na[k-1]+1;
numb=numb-na[n-1];
if(numb<=m)
printf("%lld\n",numb);
else
printf("Impossible\n");
}
return 0;
}`
enter code here
hhg
jvvv
#include<stdio.h>
int main()
{
long long int t,n,k,e,m,numb,i,j,z;
long long int na[10000];
scanf("%d",&t);
while(t–)
{
scanf("%lld%lld%lld%lld",&n,&k,&e,&m);
for(i=0;i<n;i++)
{
na[i]=0;
if(i==(n-1))
{
`for(j=0;j<e-1;j++)
{
scanf("%lld",&z);
na[i]=na[i]+z;
}
}
else
{
for(j=0;j<e;j++)
{
scanf("%lld",&z);
na[i]=na[i]+z;
}
}
}
for(i=0;i<(n-1);i++)
{
for(j=(i+1);j<(n-1);j++)
{
if(na[i]<na[j])
{ numb=na[i];
na[i]=na[j];
na[j]=numb;
}
}
}
numb=na[k-1]+1;
numb=numb-na[n-1];
if(numb<=m)
printf("%lld\n",numb);
else
printf("Impossible\n");
}
return 0;
}
#include<stdio.h>
#include<algorithm>
int main(){
long long int t,n,k,e,m,i,j,sum,x,y,z,ans;
scanf("%lld",&t);
while(t--){
scanf("%lld %lld %lld %lld",&n,&k,&e,&m);int a[n-1];
for(i=0;i<(n-1);i++)
{sum=0;
for(j=0;j<e;j++){ scanf("%lld",&x);sum+=x;}
a[i]=sum;
}std::sort(a,a+n-1);
y=a[n-k-1];ans=y;
for(j=0;j<e-1;j++){scanf("%lld",&z);ans=ans-z;}
if(ans=>0 && ans<=m)printf("%lld\n",ans);else if(ans>m)printf("Impossible\n"); else printf("0\n");
}
return 0;
}
https://www.codechef.com/viewsolution/13147275/
@Sergey Kulik @Vasya Antoniuk @Kevin Atienza
where is my solution going wrong ?
Help me what wrong with this???
#include<stdio.h>
#include<stdlib.h>
int main(){
long o,N,K,E,M,i,j,t,u,y=1;
scanf("%ld",&o);
while(o--){
int z=0;
y=1;
scanf(" %ld %ld %ld %ld",&N,&K,&E,&M);
long s[N];
for(i=0;i<(N-1);i++){
s[i]=0;
for(j=0;j<E;j++){
scanf(" %ld",&t); s[i]+=t;}}
s[N-1]=0;
for(i=0;i<(E-1);i++){scanf(" %ld",&t); s[N-1]+=t;}
for(i=0;i<(N-1);i++){
if(s[N-1]>s[i]) z++;} if(z>=(N-K)) {printf("%d",0);} else{
u=s[N-1];
while(z<(N-K)){
for(j=0;j<(N-1);j++){if(s[j]>=s[N-1]){t=s[j]; break;}}
for(i=j;i<(N-1);i++){
if((s[i]>=s[N-1])&&(s[i]<t)) t=s[i];}
if((t-u)<M) s[N-1]=t+1; else{printf("Impossible"); y=0; break;}
z=0;
for(i=0;i<(N-1);i++){
if(s[N-1]>s[i]) z++;}
}if(y==1) printf("%d",(t-u+1));}}return 0;}
Your code fails at this test case
Compilation Successful
Input (stdin)
1
4 2 3 11
10 10 10
10 10 10
10 10 10
10 10
Your Output
Impossible
Expected Output
11
I feel the error is here-
for(i=0; i<=10;i++)
{
if((sum + i) > mark[n-k-1])
{
ans=i;
flag=1;
break;
}
}
I think i should be less than or equal to m, instead of 10 in loop condition. Try it and tell.
Could someone please help me find the error?
#include
#include
using namespace std;
int main(){
long long t,n,m,e,k;
long long sum[10000]={};
long s;
int pos=0;
cin>>t;
for(int i=0;i<t;i++){
cin >> n >> k>>e>>m;
long int j;
for(j=0;j<n-1;j++){
s=0;
for(int l=0;l<e;l++){
cin>>s;
sum[j]+=s;
}
}
s=0;pos=j;
for(int l=0;l<e-1;l++){
cin>>s;
sum[j]+=s;
}
sort(sum,sum+pos);
long long x = sum[n-k-1]-sum[pos]+1;
if(x<0) cout<<0<<endl;
else if(x<m) cout<<x<<endl;
else cout<<"Impossible"<<endl;
}
return 0;
}
Thanks!
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>