WA in the problem PIPSQUIK

Not able to figure out where i am wrong in my solution in PIPSQUIK:

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
int t;
cin>>t;
while(t–)
{
vector<pair<int,int>>v;
int n,h,d,u,li,x,bar,cnt=0,b,xi,flag=1;
cin>>n>>h>>d>>u>>li;
for(int i=0;i<n;i++)
{
cin>>bar>>x;
v.push_back(make_pair(bar,x));
}
for(int i=0;i<n;i++)
{
flag=1;
b=v[i].first; xi=v[i].second;
if(b==2)
{
if(u>=xi){flag=0;cnt++;}
}
else if(b==1)
{
if(h<=xi || h-d<=xi){flag=0;cnt++;}
}
if(flag==1 && li!=1)
{
li–;
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}

@anon61233355 You have to increment the value of cnt when li is equal to 1 as well, and you have to exit the loop if either i becomes equal to n or li becomes equal to 0.

1 Like

Thanks for replying @teddysphotos,i have implemented the concept you were telling but still i am not landed up getting AC.It still showing me WA.

Following changes i have done with my code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
int t;
cin>>t;
while(t–)
{
vector<pair<int,int>>v;
int n,h,d,u,li,x,bar,cnt=0,b,xi,flag=1;
cin>>n>>h>>d>>u>>li;
for(int i=0;i<n;i++)
{
cin>>bar>>x;
v.push_back(make_pair(bar,x));
}
for(int i=0;i<n;i++)
{
flag=1;
b=v[i].first; xi=v[i].second;
if(b==2)
{
if(u>=xi){flag=0;cnt++;}
}
else if(b==1)
{
if(h<=xi || h-d<=xi){flag=0;cnt++;}
}
if(flag==1 && li!=0)
{
li–;
cnt++;
}
if(li==0)break;
}
cout<<cnt<<endl;
}
return 0;
}

Please help me with this.

You are incrementing the count variable even after the life potion is 0. The character doesn’t pass that obstacle and thus you can’t increment it there.

1 Like

@aryan12 ,Thanks for replying,PLease see this code which i submitted at the time of contest:

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
int t;
cin>>t;
while(t–)
{
vector<pair<int,int>>v;
int n,h,d,u,li,x,bar,cnt=0,b,xi,flag=1;
cin>>n>>h>>d>>u>>li;
for(int i=0;i<n;i++)
{
cin>>bar>>x;
v.push_back(make_pair(bar,x));
}
for(int i=0;i<n;i++)
{
flag=1;
b=v[i].first; xi=v[i].second;
if(b==2)
{
if(u>=xi){flag=0;cnt++;}
}
else if(b==1)
{
if(h<=xi || h-d<=xi){flag=0;cnt++;}
}
if(flag==1 && li!=1)
{
li–;
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}

and i am doing the same thing which you are telling but i am getting WA.

1 Like

Please send the link to your code. I can’t compile it on codeblocks for some reason

1 Like

@aryan12,Sure!

This is the link to my code:

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

1 Like

You code is failing in the following test case:

Test Case

1
10 4 2 5 1
2 3
2 2
2 1
2 2
2 1
2 2
2 1
2 2
2 1
2 2

Your Output

10

Expected Output

0

Explanation

The character has only 1 life potion. In the first barrier, the height of the barrier is 3, which is higher than what he can jump. So he collides with the barrier and loses his life. Thus, the answer is 0.

Hope you understood and find out the mistake in your code
:slight_smile: :slight_smile: :slight_smile: .

1 Like

@aryan12,Thanks for your reply but your expected ouput and explaination is wrong as:

According to your test case,Answer will be 10 because he can jump 5 units.

Your Test Case:

1
10 4 2 5 1
2 3
2 2
2 1
2 2
2 1
2 2
2 1
2 2
2 1
2 2

He can duck 2 units and jump 5 units (Second last variable is how much he can jump)

and he can jump all barriers!

I ran this test case in someone’ Solution which was getting AC and output was 10.

My bad, didn’t look into the problem. Will find in a few minutes.

1 Like

Ya, so problem in your code is here

Test Case

1
10 5 1 2 1
2 3
2 2
2 2
2 2
2 2
2 2
2 2
2 2
2 2
2 2

Your output

9

Expected Output

0

Explanation

The character can only jump to a height of 2. In the first obstacle, he can’t jump to a height of 3, so loses a life potion. As his life potion becomes 0, he dies and this obstacle is not considered as pass. Thus, the answer is 0.

1 Like

@aryan12,Thank you so much it got resolved.

this is the code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long int
int t;
cin>>t;
while(t–)
{
vector<pair<int,int>>v;
int n,h,d,u,li,x,bar,cnt=0,b,xi,flag=1;
cin>>n>>h>>d>>u>>li;
for(int i=0;i<n;i++)
{
cin>>bar>>x;
v.push_back(make_pair(bar,x));
}
for(int i=0;i<n;i++)
{
flag=1;
b=v[i].first; xi=v[i].second;
if(b==2)
{
if(u>=xi){flag=0;cnt++;}
}
else if(b==1)
{
if(h<=xi || h-d<=xi){flag=0;cnt++;}
}
if(flag==1 && li!=0)
{
li–;
if(li==0)break;
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
}

if(li==0)break; was necessary in the code:
I got an AC.
but It is showing partially correct verdict with score 0/100
and on my profile it is showing Accepted.
i think theres a bug in the displaying verdict.

But thanks for your help @aryan12