Pagini recente » Istoria paginii template/jc2012 | template/preoni-2008/header | Cod sursa (job #1065745) | Monitorul de evaluare | Cod sursa (job #488743)
Cod sursa(job #488743)
#include <fstream>
using namespace std;
const char InFile[]="buline.in";
const char OutFile[]="buline.out";
const int MaxN=400005;
ifstream fin(InFile);
ofstream fout(OutFile);
int best[MaxN],st[MaxN],n,v[MaxN],sol,maxsol,a;
int main()
{
fin>>n;
best[0]=-1;
for(register int i=1;i<=n;++i)
{
fin>>v[i]>>a;
if(a==0)
{
v[i]=-v[i];
}
if(best[i-1]>=0)
{
best[i]=best[i-1]+v[i];
st[i]=st[i-1];
}
else
{
best[i]=v[i];
st[i]=i;
}
}
for(register int i=n+1;i<=(n<<1)-1;++i)
{
if(best[i-1]>=0)
{
best[i]=best[i-1]+v[i-n];
st[i]=st[i-1];
}
else
{
best[i]=v[i-n];
st[i]=i-n;
}
}
fin.close();
maxsol=best[1];
sol=1;
for(register int i=2;i<=(n<<1)-1;++i)
{
if(maxsol<best[i])
{
if(i-st[i]+1<=n)
{
maxsol=best[i];
sol=i;
}
}
}
fout<<best[sol]<<" "<<st[sol]<<" "<<sol-st[sol]+1;
fout.close();
return 0;
}