sigsegv error in code

question link

http://www.codechef.com/problems/MAXCOUNT

my code
http://www.codechef.com/viewsolution/5154203

3 Likes

Hi dude, the error for runtime is a[k]=k. You have declared an array of 150 initially but constraints of k are 1 <= A[i] <= 10000, so A[10000]=10000 will give you array out of bounds.

1 Like

its not because of that…

2 Likes

and we have to provide a space between the integers…its written in the question

2 Likes

well the error for runtime is a[k]=k. You have declared an array of 150 initially but constraints of k are 1 <= A[i] <= 10000, so A[10000]=10000 will give you array out of bounds.

the constraint is that a[i]<10000 not i<10000
as it is given…n<= 100 thus a[150] is well sufficient…
and since it is declared in integer…thus…a[i]<10000 cannot be a problem…as integer range is up to 32767

3 Likes

Himanshu I think he is right. a[10000] is not defined when you have globally declared it to be a[150].

Hey @himanshu_95, see your code gives WA for this input:
1
5
155 155 155 155 155
Check here.
This error is because you have declared a of the size of 150. See the value of A[i] ie k is from 1 to 10000. Also on this for loop you need to change “n” to max limit of input ie 10000.

for(j=1;j<n;j++)
	{
		if(b[j-1]<b[j])
		{
			if(b[j]>max)
			{max=b[j];
			q=j;}
		}
	}

This is the AC version of your code. please look at it properly.
If people from iiit and nsit say something, people from ipu should listen very carefully.

1 Like

roman28…don’t underestimate the power of an ipu student…
its not about the college…its about the hard work of a student…

4 Likes

…lol… :smiley: