I have a problem with running the program

I've tryed to make a program which one calculate the maximum subsequence from a vector.
example:
ss1.in : 7
5 -6 3 4 -2 3 -3

ss1.out : 8 3 6

Subsequence maximum is (3, 4, -2, 3) which one sum is 3 + 4 - 2 + 3 = 8 and it start on the position 3 and it end on position 6 (ss1.out 8(sum) 3(start position) 6(end position)

When i try to compile it i gives me error:
0xC00000FD

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  #include <iostream>
#include <fstream>
#define NMax 6000001
using namespace std;
ifstream f("ssm.in");
ofstream g("ssm.out");
int main ()
{
    int n,s[NMax],i,st=1,dr=1,sum,summax;
    f>>n;
    for (i=1;i<=n;i++) f>>s[i];
    summax=sum=s[1];
    for (i=2;i<=n;i++)
    {
        if (sum<0)
        {
            sum=s[i];
            st=i;
        }
        else
        {
            sum=sum+s[i];
            if (summax<sum)
            {
                summax=sum;
                dr=i;
            }
        }
    }
    g<<summax<<" "<<st<<" "<<dr;
}


'st' means left and 'dr' means right


EDIT: I've solved it
I declared s[] and n global.
Last edited on
Make the array size less than 6000001. Would it be enough if the array size wil be equal for example 100?
Also take into account that indexes of arrays start from 0.
Last edited on
the problem specific that the NMax(n) must been 6kk (6 000 000)
0xC00000FD is STATUS_STACK_OVERFLOW

1
2
3
4
5
6
7
8
constexpr std::size_t NMAX = 6000001 ;

int main()
{
    static int s[NMAX] ; // **** change storage duration to static

    // TODO: fix the errors in the rest of the code.
}
Thx
I think that the topic could be close by an admin ^_^
Thank you guys.
Topic archived. No new replies allowed.