https://www.spoj.pl/problems/MAXSUMSQ/

hi i m getting wrong ans for this problem .. can anybody tell me where
i m going wrong..thx in advance..


#include<iostream>
#include<cstdio>
using namespace std;
main()
{
    int t;
    //cin>>t;
    scanf("%d",&t);
    while(t--)
    {
        long long n,a[100001],max=-1001,ts=0,sum,i,j,cnt,curr,cnt0=0;
        //cin>>n;
        scanf("%lld",&n);
        for(i=1;i<=n;i++)
            //cin>>a[i];
            scanf("%lld",&a[i]);
        for(i=1;i<=n;i++)
        {
            ts+=a[i];
            curr=a[i];
            if(a[i]==0)
                cnt0++;
            if(ts==max)
                cnt++;
            if(curr==max)
                cnt++;
            if(ts>max)
            {
                max=ts;
                cnt=1;
            }
            if(ts<0&&max>=0)
                ts=0;

        }
        if(cnt0==n)
        {
            max=0;
            cnt=n*(n+1)/2;
        }
        //cout<<max<<" "<<cnt<<"\n";
        printf("%lld %lld\n",max,cnt);
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to