UVa : 10684 (The jackpot)


// http://uva.onlinejudge.org/external/106/10684.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <bitset>
#include <utility>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;


int main ()
{
    int n;

    while ( scanf ("%d", &n) && n ) {
        int a [10000 + 10];

        for ( int i = 0; i < n; i++ )
            scanf ("%d", &a [i]);

        int dp [10000 + 10];
        memset (dp, 0, sizeof (dp));

        dp [0] = a [0];

        for ( int i = 1; i < n; i++ ) {
            if ( dp [i - 1] + a [i] > a [i] )
                dp [i] = dp [i - 1] + a [i];
            else
                dp [i] = a [i];
        }

        int maxm = 0;

        for ( int i = 0; i < n; i++ )
            maxm = max (maxm, dp [i]);

        if ( maxm == 0 )
            printf ("Losing streak.\n");
        else
            printf ("The maximum winning streak is %d.\n", maxm);
    }

    return 0;
}

// @END_OF_SOURCE_CODE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s