tc=int(input())
for t in range(tc):
n,m,k,l,r= (int(x) for x in input().split())
tbl={}
for i in range(n):
ci,p=(int(x) for x in input().split())
if ci in tbl:
tbl[ci].append§
continue
tbl[ci]=[]
tbl[ci].append§
mp=1000001
for j in tbl:
ft=j
for i in range(m):
if ft>k+1:
ft-=1
if ft<k-1:
ft+=1
else:
ft=k
if l<=ft<=r:
if mp>min(tbl[j]):
mp=min(tbl[j])
if mp==1000001:
print(-1)
else:
print(mp)
Just post link of sol. Not fill code
incorrect link…
// 20 char
check your 24th and 25th line carefully…
why did u use else if on line 14 , we can only use if right?
i did that to make sure the value doesn’t change again…
but as such yeah it should work without that as well…
bhai mera else if lgake submit hora h only if me nhi kr raha
https://www.codechef.com/viewsolution/26016013
nevermind
it doesn’t…
so what i was saying it was incorrect in my code
that’s why i used if else
but can u think of any test case which can fail if i use on only if condition
you have confused the flow of if else statements in line 18 .
eg : suppose ft = k+3
if(ft>k+1) is true and ft becomes k+2
if (ft<k-1) is false and the else condition is executed and ft becomes k.
yeah exactly,
the numbers will get skipped and you will have WA
yeah thx , but my other sol in which i didnt had else was also giving errorlink can u check this out please
suppose m=1
and ft =k+2
if(ft>k+1) is true and ft becomes k+1
if(k-1<=ft<=k+1) becomes also true then ft becomes k.
hope you got it .
ok,i got it. Thanks bro but i was wondering what if i remove ‘=’ from expression?
Then it should work fine because k-1<ft<k+1 is valid only when ft=k .
and when ft =k+1 then ft is decreased to k (and when ft =k-1 then increased to k)
because the main logic remains same .