I was trying to solve the problem George and job of contest 467C.I am getting a run time error on test 22. Does that means my code has passed first 21 test cases(I am new to codeforces). Please provide me the test case for which my code gives run time error.
MY CODE
Declare the arrays globally because global allocation takes place on heap. Constraints are such you can declare maximum size memory. Problem might be the fact that the memory size you’re trying to allocate is not possible inside main because you have done local allocation which takes place on stack. I encountered the same problem, after declaring it as global, it worked for me!!
May be there’s some mistake in your logic, See this test case,
5 2 2
17 8 3 23 2
My AC code gives 51 as the answer for this while your code gives 50.
@damn_me. I did as you said .Earlier it was giving runtime error on test 22 but now it has started giving it on 1st test case. I thinks it is due to the array size . Please check my code and see if i have taken right array size. or should i try to create an dynamic array?
My Code
for(p = i, q= m; q; q--, p--) { sum +=a[p]; }
it may be due to this fragment of code …
By looking at your code i am quite sure you must be accessing your array out of bound .
@ma5termind The point is the code is giving RTE on the first test case itself which works fine on ideone. So, how come RTE on the case on codeforces and not on ideone?
@ma5termind . I dont think In the above fragment i am accesing my code out of bound because the if statement above it
if(i < (m+j-1)) continue;
would ensure that the code reaches for loop only if there are m indexes behind it.
I am talking about the test case I have added:
5 2 2
17 8 3 23 2
My code gives 51 as the answer while your code gives 50, see the answer edit above. I have mentioned the same.