Cod sursa(job #1522496)
| Utilizator | Data | 11 noiembrie 2015 19:25:57 | |
|---|---|---|---|
| Problema | Buline | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.98 kb |
#include <iostream>
#include <cstdio>
using namespace std;
int smax,pmax,ms,imax,mx,i,j,n,s,pcur,a,V[400000],k;
int main()
{
freopen("buline.in","r",stdin);
freopen("buline.out","w",stdout);
scanf("%i",&n);
for (i=0;i<n;i++)
{
scanf("%i %i",&V[i],&k);
if (k==0)
V[i]*=-1;
V[i+n]=V[i];
}
{
s=0;
mx=-1;
pmax=1;
pcur=1;
smax=1;
for (i=1;i<=2*n;i++)
{
if (i-pcur>=n-1)
{
s-=V[pcur%n];
pcur++;
}
else ;
s+=V[i%n];
if (s>=mx)
{
mx=s;
pmax=pcur;
smax=i;
}
else if (s<0)
{
pcur=i+1;
s=0;
}
}
}
// if (mx==0) cout<<0<<" "<<0<<" "<<0;
cout<<mx<<" "<<pmax%n+1<<" "<<smax-pmax+1;
}
