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;
}
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–){
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
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;
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;
[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){
}
}
}
`
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)