TLE in STUPMACH

int main(void)
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        long long int n,i,min,tok=0,z;
        scanf("%lld",&n);
        long long int s[n];
        for(i=0;i<n;i++)
        {
            scanf("%lld",&s[i]);
        }
        min=s[0];
        while(s[0]>0)
        {
            for(i=0;i<n;i++)
            {
                if(min>s[i])
                {
                min=s[i];
                z=i;
                }
            }
            for(i=0;i<n;i++)
            {
                s[i]-=min;
            }
            tok+=min*n;
            n=z;
        }
        printf("%lld\n",tok);
    }

}

Try initializing z with 0 and check whether the error remains. Please provide the question link too.

1 Like

[STUPMACH Problem - CodeChef]
i didn’t work by z=0