Runtime error in code

link to question : http://codeforces.com/contest/817/problem/B

link to solution : http://codeforces.com/contest/817/submission/27807533

Getting runtime error on 5th test case .

Can’t figure out why?

You are storing frequencies in the arr2 and array elements can be upto 10^9.So you can’t use an array to store frequencies and instead of arrays you should use map to store frequencies.

here is my accepted solution and if you have any doubt,please comment.
http://codeforces.com/contest/817/submission/27798017

2 Likes

Since the input array has elements of the order 10^9, you invoke index out of bounds by writing arr2[arr[b]]++.

In the case where you get the runtime error, each arr[i] is 10^9 and the size of arr2 is 10^5. Hence the index out of bounds.

Got AC using Map
Thanks!!

1 Like