Kayaks - Runtime Error C++

I tried my best to optimize it.
But, it still shows runtime error.
Please help.

My Code Link:
http://www.codechef.com/viewsolution/1126929

You don’t need optimizations to get rid of the current error. You are getting a Rumtime error SIGSEGV. See the reasons why you could get a SIGSEGV http://www.codechef.com/wiki/faq#Why_do_I_get_a_SIGSEGV.

	for(i=0;i<n;i++)
	{
		a[i][0]=i;
		cin>>a[i][1];//w	Strength

In the lines above you are accessing the array elements a[i][0], a[i][1] and i could be as large as n and n<=10^5. But your array declaration is just a[10][3] hence you will end up making some invalid memory access after i crosses 10 resulting in a SIGSEGV.

1 Like