Showing error but logic seems fine

sol: https://ide.codingblocks.com/s/388601

prob: https://hack.codingblocks.com/app/contests/1975/424/problem

please run it and check

Hello @raghav007 actually there was some network issue thats why is was not able to tell your error in the code:
you can continue with any other problem i will go through your code and tell you what is wrong.

Hello @raghav007 it is giving segmentation fault because you have to take input only the single input. i.e only number n but you are taking input for array elements array as well.
your logic is wrong.
you are taking unnecessarily inputs this is the reason it is resulting into segmentation fault.
because there is no input being provided but you are seeking input in your code.
you have to think something else.
if you want to discuss the another approach then you can ask here.
and if you want to try again and then ask you can do that way as well.
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.