Tuesday, 7 May 2013

UVa 507 - Jill Rides Again Solution


#include<iostream>
#include<cstdio>
#include<list>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<queue>
#include<deque>
#include<iterator>
#include<assert.h>
#include<bitset>
#include<climits>
#include<ctime>
#include<complex>

using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define LL long long

#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define KS printf("Case %d: ",kk++)

#define MOD 1000000007
#define MX 100010


int main()
{
    int tc,kk=1,n,m,arr[20005];
    cin>>tc;
    while(tc--)
    {
        cin>>n;
        int tmp=0,mx=0,st=1,stf=1,edf=-1;

        for(int i=1;i<n;i++)
        {
            S(arr[i]);
            tmp+=arr[i];
            if(tmp<0) tmp=0,st=i+1;
            if(tmp>mx || (tmp==mx && i-st>edf-stf)) mx=tmp, edf=i,stf=st;
        }

        if(!mx) cout<<"Route "<<kk++<<" has no nice parts"<<endl;
        else    cout<<"The nicest part of route "<<kk++<<" is between stops "<<stf<<" and "<<edf+1<<endl;
    }
    return 0;
}

No comments:

Post a Comment