@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.
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.
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
.
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.
#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.