George and Job codeforces (DP). Please help.

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.

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!! :slight_smile:

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.

1 Like

@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.

@baljitsingh See the edit, I have added one test case

@damn_me , Are you talking about input? But it is giving right output on this test case

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.

Thanks @damn_me . My logic was bit wrong. I corrected it and it got accepted

1 Like

@baljitsingh Happy to help… :slight_smile: