codechef.com/problems/WALKFAST

What test case might be failing this code?

WALKFAST

Here’s a random testcase your solution fails on:

1
17 8 5 7 7 87 38 5
-990 -971 -893 -794 -694 -248 -243 -140 -40 317 328 387 582 779 783 897 916

(the answer should be 48198).

Edit:

Although there’s an element of Undefined Behaviour here as you are not initialising reachTrainOnTime.

Ok. initialized the variable.
The following solution didn’t work.
If block uncommented
This one worked.
If block commented
Is there some data type issue?

pts[300]
for(i=1;i<=N;i++)cin>>pts[i];

N can be up to 300, in which case this is and out-of-bounds access and so, Undefined Behaviour.

Try this again, this time with pts[301].

1 Like

Changed it to pts[301]

Same behavior repeats.

This works. If block commented
This doesn’tIf block uncommented

Consider the testcase:

2
1 1 1 1 1 60 46 15
-14
4 1 2 4 3 79 24 85
-764 122 495 726

Edit:

Wait, scratch that - it violates the constraints. Coming up with a better one …

Edit2:

There - I think this is right:

2
4 1 4 2 3 10 1 20
0 2 3 1000
4 1 4 2 3 100 1 1
0 1 2 1000

Edit3:

This one is more striking:

2
4 1 2 3 4 1 1 2 
0 1 2 3
4 1 4 2 3 100 1 1
0 1 999 1000
1 Like

@ssjgz You debug codes like a pro. :clap:

3 Likes

Variable reachTrainOnTime had to be reset to 0 after each test case.
This was missing earlier.

Working solution:
If block uncommented, variable reset to 0

1 Like

I wonder if it is due to good shell scripting skills (if you know what I mean) :wink:

1 Like