Hey Ankur,

Why dont u just modify the findx function itself to return the frequency of
occurence of maxsum as well.

On Sun, Mar 13, 2011 at 12:26 PM, Ankur Khurana <ankur.kkhur...@gmail.com>wrote:

> https://www.spoj.pl/problems/MAXSUMSQ/
>
>  Hi in above problem , i am getting TLE but according to given contraints ,
> i think my code is good enough to run. Can any body help me here
>
>
>
> #include <vector>
> #include <map>
> #include <algorithm>
> #include <cstring>
> #include <iostream>
> #include <cstdio>
> #include <cmath>
> #include <cstdlib>
> #include <climits>
> #define VI vector <int>
> typedef long long int LL;
> using namespace std;
> VI v;
> LL x,nos;
>
> //finding maximum sum subsequence
> LL findx()
> {
>     int sz=v.size();
>     LL maxsum=INT_MIN;
>     int maxstart=0,maxend=0;
>     LL currentsum=0;
>     int currentstart=0,currentend=0;
>
     int freq=0;

>     for(currentend=0;currentend<sz;currentend++)
>     {
>         currentsum=currentsum+v[currentend];
>
>

         if(currentsum==maxsum) {
               freq++;
        }

> if(currentsum>maxsum)
>         {
>             maxsum=currentsum;
>             maxstart=currentstart;
>             maxend=currentend;
>
              freq=0;

>         }
>         if(currentsum<0)
>         {
>             currentstart=currentend+1;
>             currentsum=0;
>         }
>     }
>
> return maxsum;
> }
>
>
> // main Program
> int main()
> {
>   //  freopen("input.txt","r",stdin);
>     int test;
>     int num;
>     map <LL , LL> m;
>     cin>>test;
>     LL sum=0;
>     int n;
>
>     int i;
>
>
>     while(test--)
>     {
>         sum=0;
>         nos=0;
>         m.clear();
>         m[0]=1;
>         scanf("%d",&n);
>         v.resize(n);
>         for(i=0;i<n;i++)
>         {
>            scanf("%d",&v[i]);
>         }
>         x=findx();
>         nos=0;
>
    //Remove this for loop. No need.

>         for(i=0;i<n;i++)
>         {
>             sum=sum+v[i];
>             nos=nos+m[sum-x];
>             m[sum]++;
>         }
>       cout<<x<<" "<<nos<<endl;
>     }
>
> return 0;
> }
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@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.
>

This shld help.

Cheers
Nikhil Jindal
https://sites.google.com/site/aboutnikhiljindal/

Please access the attached hyperlink for an important electronic communications 
disclaimer: http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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