Hi everyone can you please take a look on my solution and tell me where I’m doing it wrong because I didn’t manage to solve it CodeChef: Practical coding for everyone. It is written in C.I tried many test cases and it worked in all of them.

Thank you!

One mistake is that your variable score is an int. It can be larger than the range of int, as D[i] can be as large as 10^4 and number of villages, n, can be as large as 10^5. Together, they can produce score which can be larger than the range of int, so take long long there instead of int.

Check this test cases… Your code fails on some test cases…

1 Like

OK fixed that but still getting WA.

Some of sample test cases are :

Thanks for the answer,now I understand where my algorithm doesn’t work!You are awesome!

1 Like