spoj MAXSUB wrong answer
here is my code to http://www.spoj.com/problems/MAXSUB/
#include<stdio.h>
#define MOD 1000000009
int main()
{
long long int t,n,i,flag,s,a[100000],max,c;
scanf("%lld",&t);
while(t--)
{
c=0;
flag=0;
scanf("%lld",&n);
s=0;
max=a[0];
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
if(a[i]>0)
{
s=s+a[i];
flag=1;
}
else
{
if(a[i]>=max)
{
max=a[i];
}
}
}
for(i=0;i<n;i++)
{
if(a[i]==max)
c++;
}
if(flag==1)
printf("%lld %lld\n",s%MOD,1);
else
{
printf("%lld %lld\n",max%MOD,c%MOD);
}}
return 0;
}
basically am checking if any element is positive and adding all those
positive elements and if none is positive then counting maximum element in
that
what am getting is wrong answer every time dont know why help would e
appreciated. thanx
No comments:
Post a Comment