Pagini recente » Cod sursa (job #1191813) | Cod sursa (job #296556)
Cod sursa(job #296556)
// buline.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
int i,e[400001],smax=-200000000,semn,st=1,dr=1,l,n;
int f[400001];
int main()
{
freopen("buline.in","r",stdin);
freopen("buline.out","w",stdout);
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d %d",&f[i],&semn);
if(semn==0)
f[i]=-f[i];
e[i]=e[i-1]+f[i];
}
for(i=n+1;i<2*n;i++)
e[i]=e[i-1]+f[i-n];
for(i=1;i<2*n;i++)
{
if(i-n==st)
break;
if(e[i]-e[st-1]>smax)
{
dr=i;
smax=e[i]-e[st-1];
}
if(e[i]-e[st-1]<0)
st=i+1;
}
l=dr-st+1;
printf("%d %d %d",smax,st,l);
return 0;
}