PIPSQUIK - Editorial

// It always shows wrong solution even though it is right when checked the sample on another compiler
#include
using namespace std;

int main()
{int T,n,h,y1,y2,l,x,y,z,w,bar;
cin>>T;
for(x=1;x<=T;x++)
{cin>>n>>h>>y1>>y2>>l;
int arr[n][2];
bar=0;
for(w=0;w<n;w++)
{for(z=0;z<=1;z++) {cin>>arr[w][z];};}
for(y=0;y<n;y++)
{if(arr[y][0]==1)
{if(arr[y][1]<h-y1&&l>1){l–;bar++;}
if(arr[y][1]>=h-y1){bar++;}
;}
if(arr[y][0]==2)
{if(arr[y][1]>y2&&l>1){l–;bar++;}
if(arr[y][1]<=y2){bar++;}
;}
;}
cout<<bar<<endl
;}
return 0;
}

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

This is my solution in py3.6.
I have tried again and again but it is giving me run time error(nzec).
If anyone can help me with it,please.

try:
t=int(input())
for _ in range(t):
n,h,y1,y2,l=list(map(int,input().split()))
c=0
for __ in range(n):
t,x=list(map(int,input().split()))
if(t==1):
if((h-y1<=x)):
c+=1
else:
if(l>1):
c+=1
l-=1
else:
if(y2>=x):
c+=1
else:
if(l>1):
c+=1
l-=1
print©
#print(l)
except:
pass

can somebody tell why i am getting wrong answer through this code???

@sachin_yadav What is wrong with my solution? It returns the expected output on my compiler when I enter the example test case. I am using XCode on mac.

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

I checked test cases manually and below is the calculation
Test case 1
H=5, Y1=1, Y2=2 and L=3
barrier 1 > type 2 > X=2 > H+Y2=7 greater than X=2. true and crossed
barrier 2 > type 2 > X=1 > H+Y2=7 greater than X=1. true and crossed
barrier 3 > type 1 > X=10 > H-Y1=4 less than X=10. true and crossed
barrier 4 > type 2 > X=8 > H+Y2=7 greater than X=8. FALSE and crossed with alchemy 1of3
barrier 5 > type 2 > X=4 > H+Y2=7 greater than X=4. true and crossed
barrier 6 > type 1 > X=2 > H-Y1=4 less than X=2. FALSE and crossed with alchemy 2of3

In the end he crosses all 6 barriers with 1 alchemy life left. But in test case output is given as 5.

Output of test case 2 is also wrong.
I think output of test cases is wrong in this case except test case 3.

This is my code in pyth 3.6 can anyone please point out the error in it:
https://www.codechef.com/viewsolution/32319194

Someone please review this code. I can’t understand where i went wrong.

T=int(input())
result=[]
if 1<=T<=100:
    for t in range(T):
        NHYYL = list(map(int,input().split(' ')))
        N = NHYYL[0]
        H = NHYYL[1]
        Y1 = NHYYL[2]
        Y2 = NHYYL[3]
        L = NHYYL[4] 
        Tlist = []
        Xlist = []
        count=0
        for n in range(N):
            TX = list(map(int,input().split(' ')))
            Tlist.append(TX[0])
            Xlist.append(TX[1])
        for x in range(len(Xlist)):
            if Tlist[x]==1:
                if Xlist[x]>=H-Y1:
                    count+=1
                else:
                    if L>0:
                        L-=1
                        if L>0:
                            count+=1
                    
            else:
                if Xlist[x]<=Y2:
                    count+=1
                else:
                    if L>0:
                        L-=1
                        if L>0:
                            count+=1
        result.append(count)
              
for r in result:
    print(r)

Hey, there!
It’s been really long since you made this post. It’s quiet possible you have already understood what your mistake was. But I’ll still point it out to you in case you haven’t.
In type two barrier, the height of Edward is irrelevant. You don’t have to compare (H+Y2) with the height of the barrier. Instead you only have to compare Y2 with the height of the barrier.
It doesn’t matter how tall Edward is. What matters is whether he can jump high enough to cross the barrier or not.

I got runtime error in the code,when I submitted it.
please tell me its solution.
here is my code:

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
{
Scanner sc=new Scanner(System.in);
int t=Integer.parseInt(sc.nextLine());
while(t–>0)
{
String line=sc.nextLine();
String[] data=line.split(" “);
int n=Integer.parseInt(data[0]);
int h=Integer.parseInt(data[1]);
int duck=Integer.parseInt(data[2]);
int jump=Integer.parseInt(data[3]);
int life=Integer.parseInt(data[4]);
int crossedBarriers=0;
while(n–>0)
{
String line1=sc.nextLine();
String[] data1=line1.split(” “);
int type=Integer.parseInt(data1[0]);
int x=Integer.parseInt(data1[1]);
if(type==1 && h-duck<=x)
{
crossedBarriers++;
}
else if(type==2 && jump>=x)
{
crossedBarriers++;
}
else
{
if(life==1)
break;
else
{
life–;
crossedBarriers++;
}
}
}
System.out.print(crossedBarriers+”\n");

   }
	
}

}

Hello @sachin_yadav, i just don’t understand why the compiler is showing wrong answer also maybe its a typing mistake or something but your test case number 2’s answer should be 1 instead of 0 because l is 1.

#include
using namespace std;
void take()
{
int n,h,y1,y2,l,barrier=0;
cin>>n>>h>>y1>>y2>>l;
int t,x;
while(n)
{
cin>>t>>x;
if(t==1){

			if((h-y1)<x)
			barrier++;
			else 
				if(l!=0)
				{
					l--;
					barrier++;
				}
		}
			
			if(t==2)
				
			{if(y2>x)
			barrier++;
			else 
				if(l!=0)
				{
					barrier++;
					l--;
				}
					
			
		}
		n--;
	}
	cout<<barrier<<endl;

}
main()
{
int t;
cin>>t;
while(t)
{
take();
t–;
}
}

can anyone please help me with whats wrong in this code
#include <bits/stdc++.h>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t–)
{
int n,h,y1,y2,l,type,hb,count=0;
cin >> n >> h >> y1 >> y2 >> l;
while(n–)
{
cin >> type >> hb;
if(type == 1) //duck
{
if(h-y1 <= hb)
{
count++;
continue;
}
}
if(type == 2) //jump
{
if(y2 >= hb)
{
count++;
continue;
}
}
l–;
if(l==0)
break;
count++;
}
cout << count << endl;
}
return 0;
}