SIGSEGV error in Team Split -plz help

i think this error is due to this statement…
int s[3000000];
plz help how to allocate this size array…

1 Like

declare array outside main() function means make its globle array…
int s[3000000];
int main()
and use it


specially this query related to ongoing contest so please don’t ask…specially contest is for checking your skill not queries.
After contest you can ask any query


@maheiitr why it was giving error…when i used this declaration inside main…but not giving when i declared outside of main…


Global declaration reserves memory on the static memory which is large enough to not impose a memory problem. But local declarations reserves memory on the stack which it’s memory is limited. So you can’t declare an array as a local object with a large amount of memory otherwise you get out of the memory range which is known as a Stack Overflow


hope you understand …:slight_smile:


ya i got it…thanks

Do not try to use array in this prob as u need only the current and the previous value at any state
try to implement this logic it will save u lot of memory in future competition …

1 Like

I used global declaration for the array
but I’m still getting runtime error

You have taken the variables to be Integer data types. So when you are doing the following multiplication temptempa then the value exceeds the range of integers and hence become negative. So this would give a runtime error. So better take the data types to be Long Long Int.

declare your array globally with long long data type…dnt use unsigned long long,otherwise abs will gve WA

that worked

@zargus thanks buddy… :slight_smile: