Cod sursa(job #25956)

Utilizator Gaby_mMititelu Gabriel Gaby_m Data 4 martie 2007 16:51:52
Problema Buline Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream.h>


int main()
{
long smax,st,n,lg,sum,poz,i,j,x,a[200000];
ifstream f("buline.in");
f>>n;
for (i=1;i<=n;i++)
       {
       f>>a[i]>>x;
       if (x==0) a[i]=-a[i];
       }
f.close();
smax=sum=0;
st=poz=0;
lg=1;
for (i=1;i<2*n;i++)
     {
	if(i>n)  j=i-n;
	     else j=i;
	if (sum<0)
	      {
	      sum=a[j];
	      st=j;
	      lg=1;
	      }
	      else
		  sum+=a[j];

	if ( smax<sum)
		 {
		 smax=sum;
		 lg=i-st+1;
		 poz=i;
		 }
	}
poz--;
while (a[poz]>=0)
      poz--;
poz++;
ofstream g("buline.out");
if (poz>n) g<<smax<<" "<<poz-n<<" "<<lg;
   else g<<smax<<" "<<poz<<" "<<lg;
g<<"\n";
g.close();
return 0;
}