CHEFELEC - Editorial

yeah thats true, but for some reason my solution is not accepted.
Could you help me with some corner case I might be missing.
https://www.codechef.com/viewsolution/10866465

One case may be is, when both left and right side needs same wire length, consider the side which can connect to more villages, usually it would mean connecting to the right side, as towards left as there would be only one village without electricity.

Here, ‘i’ never reaches to n or above because i=j and j is always initialised to n-1. So it goes into infinite loop. Isn’t it ? Help me if I am wrong anywhere ?

In an array/string the indexing is 0,1,…,n-1 for n number of elements .Here i and j are acting like keys so they will always access the complete array and this will be hence a O(n) solution.

1 Like

Can some one tell me whats wrong in my solution?
https://www.codechef.com/viewsolution/10736188

Can anyone tell me why my answer is wrong,i am not able to find why it shows wrong answer.
https://www.codechef.com/viewsolution/10783010

i could not understand whats wrong in my code…please check this out
https://www.codechef.com/viewsolution/10713327

I think this approach will give wrong answer for the test case
1000000
1 2 3 4 5 7 8
as its answer should be 7
but according to given editorial will come to be 5 ?
Please can anyone explain the mistake!

1 Like

Cc is not just checking the result and time it takes to produce results, they are looking any if condition present in the code, if it is they reject with WA, it is misdleading

in the last for loop:
for (int k = i + 1; k < j; k++)
maxDiff = max(maxDiff, x[k + 1] - x[k]);
K should start from i i.e. k=i,
Please confirm my doubt

Please can anyone find error in my code? I am not able to figure where it is failing?
https://www.codechef.com/viewsolution/16029066
Task 2 and 3 of subtask 2 is showing AC but others WA.

Can we do it like this??
We can map the distances to their respective value of ‘0’ or ‘1’.
After this we can apply sorting to map and for every value of ‘0’ we need to find the rightmost 1??