WALKFAST problem

Hey, I am getting wrong answer to WALKFAST problem. I tried to figure out which test case is failing but to no avail. Please help me out

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

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

1 Like

Thanks! I am new to CodeChef. I just pasted the solution link instead. :slight_smile:

1 Like

Thanks :slight_smile: Your solution gives the wrong answer for the following test input:

1
8 1 8 1 4 92 70 45
-70 -56 -49 -7 -1 2 19 45

(the answer should be 9239).

2 Likes

Thanks! It seems I was returning time instead of time1. I corrected it and your test case works now. Still, the submission is showing wrong :frowning:

updated: CodeChef: Practical coding for everyone

Any help is appreciated. TIA

1 Like

Whats even more interesting is that some guy copied my code (including the variable names) and submitted . He got it correct.
Here’s his code : CodeChef: Practical coding for everyone

There’s one obvious bug remaining now, and it’s an easy one - just compare your solution with @everule1’s (they are not identical copies of each other) and you’ll see what it is :slight_smile:

2 Likes

SOLUTION IN JAVASCRIPT :-
process.stdin.resume();
process.stdin.setEncoding(‘utf8’);

var arr = ‘’;
process.stdin.on(‘data’, function (chunk) {
arr += chunk;
});

process.stdin.on(‘end’, function () {
arr = arr.split(‘\n’);
let t = Number(arr.shift());
loop: for (let s = 0; s < t; s++) {
const [n,a,b,c,d,p,q,y] = arr[s*2].split(’ ‘).map(Number);
const nArray = arr[s*2+1].split(’ ').map(Number);
const walkTime = Math.abs((nArray[b-1] - nArray[a-1])*p);
const walkToTrainTime = Math.abs((nArray[c-1] - nArray[a-1])*p);
if (walkToTrainTime > y) {
console.log(walkTime);
continue;
}
const trainTime = Math.abs((nArray[c-1] - nArray[d-1])*q);
const trainToBCityTime = Math.abs((nArray[d-1] - nArray[b-1])*p);
const viaTrainTime = y + trainTime + trainToBCityTime;
// console.log({walkTime,walkToTrainTime,trainTime,trainToBCityTime,viaTrainTime});
console.log(walkTime < viaTrainTime ? walkTime : viaTrainTime);
}
});