Please HELP---Why I am getting SIGSEGV?---DELISH

Question Link----[DELISH Problem - CodeChef]
My Solution-----[ Solution: 47308606 | CodeChef]

I just used basic dynamic Problem approach. In my opinion this the variation of
MINIMUM SUBSET DIFF. with added condition for negative values…
My code is running fine in sublime text but is giving SIGSEGV on codechef.
What is wrong in my code…
Please help.

Thank you for helping…
Please help me in finding where is error in my code since I am getting runtime error…

Your solution has an out-of-bounds access with the sample test input:

[simon@simon-laptop][13:58:10]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling manthanvats16-DELISH.cpp
+ g++ -std=c++14 manthanvats16-DELISH.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
manthanvats16-DELISH.cpp: In function ‘void solve()’:
manthanvats16-DELISH.cpp:11:9: warning: unused variable ‘sum_pos’ [-Wunused-variable]
   int n,sum_pos=0,sum_neg=0;
         ^~~~~~~
+ set +x
Successful
[simon@simon-laptop][13:58:18]
[~/devel/hackerrank/otherpeoples]>echo "2
5
1 2 3 4 5
4
1 1 -1 -1" | ./a.out
manthanvats16-DELISH.cpp:38:49: runtime error: index 5 out of bounds for type 'bool [*]'
13
4

I made the changes and now i am not getting segmentation fault. Thank you very much…
I also want to ask you how you debugged my code…
Is there any way I can do it myself like you did??

1 Like

All the information you need is in that post :slight_smile:

1 Like