CHARGES - Editorial

All of the Editorialist, Tester and Setter solutions give:

0
0
0
0
0
0
0
0
0

for the test input:

1
1 9
1
1 1 1 1 1 1 1 1 1

If printing out a single 0 gets AC, I guess the testcases must be pretty weak.

1 Like

Can someone please explain why this code is giving Runtime Error?It’s working fine for the given TC,but after submitting it’s giving Runtime Error RE (SIGSEGV).
Thank you!

Solution

[simon@simon-laptop][19:08:05]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling cookieg13-CHARGES.cpp
+ g++ -std=c++14 cookieg13-CHARGES.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
cookieg13-CHARGES.cpp: In function β€˜int main()’:
cookieg13-CHARGES.cpp:25:17: warning: unused variable β€˜i’ [-Wunused-variable]
         int N,K,i,TotalDist=0;
                 ^
+ set +x
Successful
[simon@simon-laptop][19:08:14]
[~/devel/hackerrank/otherpeoples]>echo "1
3 3
010
2 1 3" | ./a.out
cookieg13-CHARGES.cpp:38:23: runtime error: index 2 out of bounds for type 'int [*]'
cookieg13-CHARGES.cpp:42:32: runtime error: index 2 out of bounds for type 'int [*]'
4
3
2