Pagini recente » Istoria paginii runda/oji.2k16/clasament | Monitorul de evaluare | Cod sursa (job #1371499) | Cod sursa (job #1218773) | Cod sursa (job #2469500)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("buline.in");
ofstream fout("buline.out");
int n,i,b,a,poz,pozm,lm,l,v[400002];
long long smax,best[400002];
int main()
{
fin>>n;
for(i=1; i<=n; i++)
{
fin>>a>>b;
if(b==0)
{
v[i]=v[n+i]=-a;
}
else v[i]=v[n+i]=a;
}
smax=v[1];
n=2*n;
poz=1;
l=1;
for(i=1; i<=n; i++)
{
best[i]=v[i];
if(best[i]<best[i-1]+v[i])
{
if(l<n/2)best[i]=best[i-1]+v[i],l++;
else best[i]=v[i];
}
else
{
poz=i;
l=1;
}
if(smax<best[i]&&l<n) smax=best[i],pozm=poz,lm=l;
}
fout<<smax<<" "<<pozm<<" "<<lm;
return 0;
}