Cod sursa(job #1164006)

Utilizator nimicLeoveanu Mihaita Alexandru nimic Data 1 aprilie 2014 19:56:03
Problema Buline Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<fstream>
using namespace std;
ifstream in("buline.in");
ofstream out("buline.out");

const int nmax = 200006;
long v[nmax], n, sact, beg, bestbeg, bestend, smax = -10000000000, lung, lmax;

int main(){
	int player_unu=0;

	in>>n;
	for(int i = 0 ; i<n; i++)
	{
		int aux;
		in>>v[i]>>aux;

		if(aux==0)
			v[i] = -v[i];
	}

	for(int i = 0; i<n; i++)
        {
            if(sact<0)
            {
                beg = i;
                sact = v[i];
				lung = 1;
            }
            else{
				sact += v[i];
				lung++;
			}
 
            if(sact>smax || (sact==smax && beg<bestbeg) || (sact==smax && beg==bestbeg && lung>lmax))
            {
                smax = sact;
                bestbeg = beg;
				lmax = lung;
            }
        }
	for(int i = 0; bestbeg>=i && sact>=0; i++)
            {
                sact += v[i];
				lung++;
 
                if(sact>smax)
                {
                    smax = sact;
                    bestbeg = beg;
					lmax = lung;
                }
            }

	out<<smax<<" "<<bestbeg+1<<" "<<lmax<<'\n';
	return player_unu;
}